aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAmaan Qureshi <amaanq12@gmail.com>2024-01-26 02:48:26 -0500
committerAmaan Qureshi <amaanq12@gmail.com>2024-02-08 18:59:04 -0500
commit76700e147bfab7630e6b97f91b32397175e8153f (patch)
treed94fbad3f92ac816fcbb0cf65ada16adb952947b
parentfeat(readline): add parser tree-sitter-readline (#6058) (diff)
downloadnvim-treesitter-76700e147bfab7630e6b97f91b32397175e8153f.tar
nvim-treesitter-76700e147bfab7630e6b97f91b32397175e8153f.tar.gz
nvim-treesitter-76700e147bfab7630e6b97f91b32397175e8153f.tar.bz2
nvim-treesitter-76700e147bfab7630e6b97f91b32397175e8153f.tar.lz
nvim-treesitter-76700e147bfab7630e6b97f91b32397175e8153f.tar.xz
nvim-treesitter-76700e147bfab7630e6b97f91b32397175e8153f.tar.zst
nvim-treesitter-76700e147bfab7630e6b97f91b32397175e8153f.zip
feat(d)!: switch upstream parser to `gdamore/tree-sitter-d`
-rw-r--r--README.md2
-rw-r--r--lockfile.json2
-rw-r--r--lua/nvim-treesitter/parsers.lua9
-rw-r--r--queries/d/folds.scm5
-rw-r--r--queries/d/highlights.scm525
-rw-r--r--queries/d/indents.scm22
-rw-r--r--queries/d/injections.scm23
-rw-r--r--queries/d/locals.scm79
8 files changed, 429 insertions, 238 deletions
diff --git a/README.md b/README.md
index f62213b41..24cc66b58 100644
--- a/README.md
+++ b/README.md
@@ -205,7 +205,7 @@ We are looking for maintainers to add more parsers and to write query files for
- [x] [csv](https://github.com/amaanq/tree-sitter-csv) (maintained by @amaanq)
- [x] [cuda](https://github.com/theHamsta/tree-sitter-cuda) (maintained by @theHamsta)
- [x] [cue](https://github.com/eonpatapon/tree-sitter-cue) (maintained by @amaanq)
-- [x] [d](https://github.com/CyberShadow/tree-sitter-d) (experimental, maintained by @nawordar)
+- [x] [d](https://github.com/gdamore/tree-sitter-d) (maintained by @amaanq)
- [x] [dart](https://github.com/UserNobody14/tree-sitter-dart) (maintained by @akinsho)
- [x] [devicetree](https://github.com/joelspadin/tree-sitter-devicetree) (maintained by @jedrzejboczar)
- [x] [dhall](https://github.com/jbellerb/tree-sitter-dhall) (maintained by @amaanq)
diff --git a/lockfile.json b/lockfile.json
index dc85a37d6..4c5cef7ea 100644
--- a/lockfile.json
+++ b/lockfile.json
@@ -96,7 +96,7 @@
"revision": "2df92e6755337e9234ad18ffef37f35d95e2ba9d"
},
"d": {
- "revision": "c2fbf21bd3aa45495fe13247e040ad5815250032"
+ "revision": "d9a1a2ed77017c23f715643f4739433a5ea7ab6f"
},
"dart": {
"revision": "f71e310a93010863f4b17a2a501ea8e2032c345b"
diff --git a/lua/nvim-treesitter/parsers.lua b/lua/nvim-treesitter/parsers.lua
index 852852986..feca033d0 100644
--- a/lua/nvim-treesitter/parsers.lua
+++ b/lua/nvim-treesitter/parsers.lua
@@ -346,13 +346,10 @@ list.cue = {
list.d = {
install_info = {
- url = "https://github.com/CyberShadow/tree-sitter-d",
- files = { "src/parser.c", "src/scanner.cc" },
- requires_generate_from_grammar = true,
+ url = "https://github.com/gdamore/tree-sitter-d",
+ files = { "src/parser.c", "src/scanner.c" },
},
- -- Generating grammar takes ~60s
- experimental = true,
- maintainers = { "@nawordar" },
+ maintainers = { "@amaanq" },
}
list.dart = {
diff --git a/queries/d/folds.scm b/queries/d/folds.scm
index be4dee45e..49d6256f6 100644
--- a/queries/d/folds.scm
+++ b/queries/d/folds.scm
@@ -1 +1,4 @@
-(block_statement) @fold
+[
+ (block_statement)
+ (aggregate_body)
+] @fold
diff --git a/queries/d/highlights.scm b/queries/d/highlights.scm
index 2b63dd48c..89ff704e7 100644
--- a/queries/d/highlights.scm
+++ b/queries/d/highlights.scm
@@ -1,275 +1,374 @@
-; Misc
+; Keywords
[
- (line_comment)
- (block_comment)
- (nesting_block_comment)
-] @comment @spell
-
-((line_comment) @comment.documentation
- (#lua-match? @comment.documentation "^///[^/]"))
-
-((line_comment) @comment.documentation
- (#lua-match? @comment.documentation "^///$"))
-
-((block_comment) @comment.documentation
- (#lua-match? @comment.documentation "^/[*][*][^*].*[*]/$"))
-
-((nesting_block_comment) @comment.documentation
- (#lua-match? @comment.documentation "^/[+][+][^+].*[+]/$"))
+ (directive)
+ (shebang)
+] @keyword.directive
[
- "("
- ")"
- "["
- "]"
- "{"
- "}"
-] @punctuation.bracket
+ (import)
+ (module)
+] @keyword.import
[
- ","
- ";"
- "."
- ":"
-] @punctuation.delimiter
+ (alias)
+ (asm)
+ (class)
+ (delegate)
+ (delete)
+ (enum)
+ (interface)
+ (invariant)
+ (mixin)
+ (pragma)
+ (struct)
+ (template)
+ (union)
+ (unittest)
+ (version)
+ (with)
+ (traits)
+ (vector)
+ (parameters_)
+ (default)
+ (goto)
+] @keyword
-[
- ".."
- "$"
-] @punctuation.special
+(function) @keyword.function
-; Constants
-[
- "__FILE_FULL_PATH__"
- "__FILE__"
- "__FUNCTION__"
- "__LINE__"
- "__MODULE__"
- "__PRETTY_FUNCTION__"
-] @constant.macro
+(synchronized) @keyword.coroutine
[
- (wysiwyg_string)
- (alternate_wysiwyg_string)
- (double_quoted_string)
- (hex_string)
- (delimited_string)
- (token_string)
-] @string
-
-(character_literal) @character
-
-(integer_literal) @number
-
-(float_literal) @number.float
+ (if)
+ (else)
+ (switch)
+ (case)
+ (break)
+] @keyword.conditional
[
- "true"
- "false"
-] @boolean
+ (do)
+ (for)
+ (foreach)
+ (foreach_reverse)
+ (while)
+ (continue)
+] @keyword.repeat
-; Functions
-(func_declarator
- (identifier) @function)
+(return) @keyword.return
[
- "__traits"
- "__vector"
- "assert"
- "is"
- "mixin"
- "pragma"
- "typeid"
-] @function.builtin
-
-(import_expression
- "import" @function.builtin)
-
-(parameter
- (var_declarator
- (identifier) @variable.parameter))
-
-(function_literal
- (identifier) @variable.parameter)
-
-(constructor
- "this" @constructor)
-
-(destructor
- "this" @constructor)
+ (abstract)
+ (deprecated)
+ (private)
+ (protected)
+ (public)
+ (package)
+ (immutable)
+ (final)
+ (const)
+ (override)
+ (static)
+] @type.qualifier
-; Keywords
[
- "case"
- "default"
- "else"
- "if"
- "switch"
-] @keyword.conditional
+ (assert)
+ (try)
+ (catch)
+ (finally)
+ (throw)
+ (nothrow)
+] @keyword.exception
[
- "break"
- "continue"
- "do"
- "for"
- "foreach"
- "foreach_reverse"
- "while"
-] @keyword.repeat
+ (cast)
+ (new)
+ (in)
+ (is)
+ (not_in)
+ (not_is)
+ (typeid)
+ (typeof)
+] @keyword.operator
[
- "__parameters"
- "alias"
- "align"
- "asm"
- "auto"
- "body"
- "class"
- "debug"
- "enum"
- "export"
- "goto"
- "interface"
- "invariant"
- "macro"
- "out"
- "override"
- "package"
- "static"
- "struct"
- "template"
- "union"
- "unittest"
- "version"
- "with"
-] @keyword
+ (lazy)
+ (align)
+ (extern)
+ (scope)
+ (ref)
+ (pure)
+ (export)
+ (shared)
+ (gshared)
+ (out)
+ (inout)
+] @keyword.storage
-[
- "delegate"
- "function"
-] @keyword.function
+(parameter_attribute
+ (return) @keyword.storage)
-"return" @keyword.return
+(parameter_attribute
+ (in) @keyword.storage)
-[
- "cast"
- "new"
-] @keyword.operator
+(parameter_attribute
+ (out) @keyword.storage)
+(debug) @keyword.debug
+
+; Operators
[
- "+"
- "++"
- "+="
- "-"
- "--"
- "-="
- "*"
- "*="
- "%"
- "%="
- "^"
- "^="
- "^^"
- "^^="
- "/"
"/="
+ "/"
+ ".."
+ "&"
+ "&="
+ "&&"
"|"
"|="
"||"
- "~"
- "~="
- "="
- "=="
- "=>"
+ "-"
+ "-="
+ "--"
+ "+"
+ "+="
+ "++"
"<"
"<="
"<<"
"<<="
">"
">="
- ">>"
">>="
- ">>>"
">>>="
+ ">>"
+ ">>>"
"!"
"!="
- "&"
- "&&"
+ "$"
+ "="
+ "=="
+ "*"
+ "*="
+ "%"
+ "%="
+ "^"
+ "^="
+ "^^"
+ "^^="
+ "~"
+ "~="
+ "@"
] @operator
+; Variables
+(identifier) @variable
+
[
- "catch"
- "finally"
- "throw"
- "try"
-] @keyword.exception
+ "exit"
+ "success"
+ "failure"
+ (this)
+ (super)
+] @variable.builtin
-"null" @constant.builtin
+(linkage_attribute
+ "("
+ _ @variable.builtin
+ ")")
-[
- "__gshared"
- "const"
- "immutable"
- "shared"
-] @keyword.storage
+; Modules
+(module_fqn
+ (identifier) @module)
-[
- "abstract"
- "deprecated"
- "extern"
- "final"
- "inout"
- "lazy"
- "nothrow"
- "private"
- "protected"
- "public"
- "pure"
- "ref"
- "scope"
- "synchronized"
-] @type.qualifier
+; Attributes
+(at_attribute
+ (identifier) @attribute)
+
+; Constants
+(enum_member
+ (identifier) @constant)
-(alias_assignment
+(manifest_declarator
.
- (identifier) @type.definition)
+ (identifier) @constant)
-(module_declaration
- "module" @keyword.import)
+; Members
+(aggregate_body
+ (variable_declaration
+ (declarator
+ (identifier) @variable.member)))
-(import_declaration
- "import" @keyword.import)
+(property_expression
+ "."
+ (identifier) @variable.member)
-(type) @type
+(type
+ "."
+ (identifier) @variable.member)
-(catch_parameter
- (qualified_identifier) @type)
+; Types
+(class_declaration
+ (class)
+ .
+ (identifier) @type)
-(var_declarations
- (qualified_identifier) @type)
+(struct_declaration
+ (struct)
+ .
+ (identifier) @type)
-(func_declaration
- (qualified_identifier) @type)
+(union_declaration
+ (union)
+ .
+ (identifier) @type)
-(parameter
- (qualified_identifier) @type)
+(enum_declaration
+ (enum)
+ .
+ (identifier) @type)
-(class_declaration
+(alias_declaration
+ (alias)
+ .
(identifier) @type)
-(fundamental_type) @type.builtin
+((identifier) @type
+ (#lua-match? @type "^[A-Z].*"))
-(module_fully_qualified_name
- (packages
- (package_name) @module))
+(type
+ .
+ (identifier) @type .)
-(module_name) @module
+[
+ (auto)
+ (void)
+ (bool)
+ (byte)
+ (ubyte)
+ (char)
+ (short)
+ (ushort)
+ (wchar)
+ (dchar)
+ (int)
+ (uint)
+ (long)
+ (ulong)
+ (real)
+ (double)
+ (float)
+ (cent)
+ (ucent)
+ (ireal)
+ (idouble)
+ (ifloat)
+ (creal)
+ (double)
+ (cfloat)
+] @type.builtin
-(at_attribute) @attribute
+; Functions
+(function_declaration
+ (identifier) @function)
-(user_defined_attribute
- "@" @attribute)
+(call_expression
+ (identifier) @function)
-; Variables
-(primary_expression
- "this" @variable.builtin)
+(call_expression
+ (type
+ (identifier) @function .))
+
+(call_expression
+ (property_expression
+ (call_expression)
+ (identifier) @function .))
+
+; Parameters
+(parameter
+ (_)
+ (identifier) @variable.parameter)
+
+(function_literal
+ "("
+ (type
+ (identifier) @variable.parameter))
+
+; Constructors
+(constructor
+ (this) @constructor)
+
+(destructor
+ (this) @constructor)
+
+(postblit
+ .
+ (this) @constructor)
+
+; Punctuation
+[
+ ";"
+ "."
+ ":"
+ ","
+ "=>"
+] @punctuation.delimiter
+
+[
+ "("
+ ")"
+ "["
+ "]"
+ "{"
+ "}"
+] @punctuation.bracket
+
+"..." @punctuation.special
+
+; Ternaries
+(ternary_expression
+ [
+ "?"
+ ":"
+ ] @keyword.conditional.ternary)
+
+; Labels
+(label
+ (identifier) @label)
+
+(goto_statement
+ (identifier) @label)
+
+; Literals
+(string_literal) @string
+
+[
+ (int_literal)
+ (float_literal)
+] @number
+
+(char_literal) @character
+
+[
+ (true)
+ (false)
+] @boolean
+
+[
+ (null)
+ (special_keyword)
+] @constant.builtin
+
+; Comments
+(comment) @comment @spell
+
+((comment) @comment.documentation
+ (#lua-match? @comment.documentation "^///[^/]"))
+
+((comment) @comment.documentation
+ (#lua-match? @comment.documentation "^///$"))
+
+((comment) @comment.documentation
+ (#lua-match? @comment.documentation "^/[*][*][^*].*[*]/$"))
+
+((comment) @comment.documentation
+ (#lua-match? @comment.documentation "^/[+][+][^+].*[+]/$"))
diff --git a/queries/d/indents.scm b/queries/d/indents.scm
index 81624cabd..c89b4e91d 100644
--- a/queries/d/indents.scm
+++ b/queries/d/indents.scm
@@ -1,20 +1,24 @@
[
+ (parameters)
+ (template_parameters)
+ (expression_statement)
+ (aggregate_body)
+ (function_body)
+ (scope_statement)
(block_statement)
(case_statement)
- (token_string)
] @indent.begin
+(comment) @indent.auto
+
[
- "("
- ")"
- "{"
+ (case)
+ (default)
"}"
- "["
"]"
] @indent.branch
[
- (line_comment)
- (block_comment)
- (nesting_block_comment)
-] @indent.ignore
+ (directive)
+ (shebang)
+] @indent.zero
diff --git a/queries/d/injections.scm b/queries/d/injections.scm
index 7437b932b..163348100 100644
--- a/queries/d/injections.scm
+++ b/queries/d/injections.scm
@@ -1,9 +1,18 @@
-([
- (line_comment)
- (block_comment)
- (nesting_block_comment)
-] @injection.content
+((comment) @injection.content
(#set! injection.language "comment"))
-((token_string_tokens) @injection.content
- (#set! injection.language "d"))
+((call_expression
+ (type) @_printf
+ (arguments
+ "("
+ .
+ (expression
+ (string_literal) @injection.content)))
+ (#eq? @_printf "printf")
+ (#offset! @injection.content 0 1 0 -1)
+ (#set! injection.language "printf"))
+
+; TODO: uncomment when asm is added
+; ((asm_inline) @injection.content
+; (#set! injection.language "asm")
+; (#set! injection.combined))
diff --git a/queries/d/locals.scm b/queries/d/locals.scm
new file mode 100644
index 000000000..1d7d617d8
--- /dev/null
+++ b/queries/d/locals.scm
@@ -0,0 +1,79 @@
+; Scopes
+[
+ (source_file)
+ (block_statement)
+ (aggregate_body)
+] @local.scope
+
+; References
+(identifier) @local.reference
+
+; Definitions
+(module_def
+ (module_declaration
+ (module_fqn) @local.definition.namespace)
+ (#set! "definition.namespace.scope" "global"))
+
+(enum_declaration
+ (enum_member
+ .
+ (identifier) @local.definition.enum))
+
+(class_declaration
+ (class)
+ .
+ (identifier) @local.definition.type)
+
+(struct_declaration
+ (struct)
+ .
+ (identifier) @local.definition.type)
+
+(union_declaration
+ (union)
+ .
+ (identifier) @local.definition.type)
+
+(enum_declaration
+ (enum)
+ .
+ (identifier) @local.definition.type)
+
+(alias_declaration
+ (alias_initializer
+ .
+ (identifier) @local.definition.type))
+
+(constructor
+ (this) @local.definition.method)
+
+(destructor
+ (this) @local.definition.method)
+
+(postblit
+ (this) @local.definition.method)
+
+(aggregate_body
+ (function_declaration
+ (identifier) @local.definition.method))
+
+(manifest_declarator
+ .
+ (identifier) @local.definition.constant)
+
+(anonymous_enum_declaration
+ (enum_member
+ .
+ (identifier) @local.definition.constant))
+
+(variable_declaration
+ (declarator
+ (identifier) @local.definition.var))
+
+(aggregate_body
+ (variable_declaration
+ (declarator
+ (identifier) @local.definition.field)))
+
+(function_declaration
+ (identifier) @local.definition.function)