Skip to content

Commit 95e0339

Browse files
committed
feat: add D syntax highlighting. Fixes #212
1 parent 5247b34 commit 95e0339

18 files changed

Lines changed: 8136 additions & 0 deletions

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ This [EclipseⓇ](https://eclipse.org) plug-in adds syntax highlighting support
3030
1. CodeQL - https://codeql.github.com/
3131
1. Crystal (`*.cr`) - https://crystal-lang.org/
3232
1. CSV (`*.cvs`) / TSV (`*.tab*`, `*.tsv*`)
33+
1. D - https://dlang.org/
3334
1. D2 - https://d2lang.com/
3435
1. Eclipse External null Annotations (`*.eea`) - https://github.com/eclipse-jdt/eclipse.jdt.core/wiki/Null-Analysis-External-Annotations#file-format
3536
1. EditorConfig - https://editorconfig.org
@@ -123,6 +124,7 @@ To install the plugin into an existing Eclipse installation do:
123124
| Amber <img src="plugin/syntaxes/amber/amber.icon.png" width=16/> | file-extensions="ab, amber" | [main@amber-lang/amber-vsc](https://github.com/amber-lang/amber-vsc/tree/c0ebd53e075698fa62efffd492a41b27bff1c227/)
124125
| ANTLR <img src="plugin/syntaxes/antlr4/icon.png" width=16/> | file-extensions="g, g4" | [master@mike-lischke/vscode-antlr4](https://github.com/mike-lischke/vscode-antlr4/tree/8408f1d50c59bc81f52795525ad41a6b50787316/)
125126
| Apache HTTP Config <img src="plugin/syntaxes/apache-http/icon.png" width=16/> | file-extensions="conf, htaccess, htgroups, htpasswd" | [master@mrmlnc/vscode-apache](https://github.com/mrmlnc/vscode-apache/tree/0585b0bb3d390fc541aa27cfcfb83b3204156be3/)
127+
| arsd.DScript <img src="plugin/syntaxes/d/icon.png" width=16/> | file-extensions="ds, dscript" | [master@Pure-D/code-d](https://github.com/Pure-D/code-d/tree/3a0825ccea623103a7027f4c1c23e5a3c38434d9/)
126128
| Astro <img src="plugin/syntaxes/astro/astro.icon.png" width=16/> | file-extensions="astro" | [main@withastro/language-tools](https://github.com/withastro/language-tools/tree/b4bcb4fc02cd960936a5faee6c9cc0ad94fc4c05/packages/vscode)
127129
| Ballerina | file-extensions="bal" | [master@ballerina-platform/ballerina-grammar](https://github.com/ballerina-platform/ballerina-grammar/tree/9c5d63039c9b257e508470da94a59d29a3c69d72/syntaxes)
128130
| bazelrc <img src="plugin/syntaxes/bazel/icon.png" width=16/> | file-extensions="bazelrc"<br />file-names=".bazelrc, bazel.rc" | [master@bazelbuild/vscode-bazel](https://github.com/bazelbuild/vscode-bazel/tree/19b4f57f6d86a46447e3915f94a1fbfe7518485b/)
@@ -133,7 +135,10 @@ To install the plugin into an existing Eclipse installation do:
133135
| Crystal <img src="plugin/syntaxes/crystal/icon.png" width=16/> | file-extensions="cr" | [master@crystal-lang-tools/vscode-crystal-lang](https://github.com/crystal-lang-tools/vscode-crystal-lang/tree/9d85621bd72b76fb5f4c81dd8357a3e6e834f7ce/) [[upstream]](https://github.com/Microsoft/vscode/blob/3f1f36333d3453f67a36b6bfb1206e9159e9c4f0/extensions/ruby/syntaxes/ruby.tmLanguage.json)
134136
| Crystal Slang <img src="plugin/syntaxes/crystal/icon.png" width=16/> | file-extensions="slang" | [master@crystal-lang-tools/vscode-crystal-lang](https://github.com/crystal-lang-tools/vscode-crystal-lang/tree/9d85621bd72b76fb5f4c81dd8357a3e6e834f7ce/)
135137
| CSV <img src="plugin/syntaxes/csv/icon.png" width=16/> | file-extensions="csv" | [master@mechatroner/vscode_rainbow_csv](https://github.com/mechatroner/vscode_rainbow_csv/tree/82f1b82272e567d6e1736fce845f94eccef6d211/)
138+
| D <img src="plugin/syntaxes/d/icon.png" width=16/> | file-extensions="d, di" | [master@Pure-D/code-d](https://github.com/Pure-D/code-d/tree/3a0825ccea623103a7027f4c1c23e5a3c38434d9/)
136139
| d2 <img src="plugin/syntaxes/d2/d2.icon.png" width=16/> | file-extensions="d2" | [master@terrastruct/d2-vscode](https://github.com/terrastruct/d2-vscode/tree/88d9716009f9b8d65bfd6dea96064c94a5cf275f/)
140+
| Diet <img src="plugin/syntaxes/d/icon.png" width=16/> | file-extensions="dt" | [master@Pure-D/code-d](https://github.com/Pure-D/code-d/tree/3a0825ccea623103a7027f4c1c23e5a3c38434d9/) [[upstream]](https://github.com/davidrios/jade-tmbundle/commit/7c1304aa5a0d916a93fd296d3dd994219ecdc90f)
141+
| DlangUI Markup Language <img src="plugin/syntaxes/d/icon.png" width=16/> | file-extensions="dml" | [master@Pure-D/code-d](https://github.com/Pure-D/code-d/tree/3a0825ccea623103a7027f4c1c23e5a3c38434d9/)
137142
| EditorConfig <img src="plugin/syntaxes/editorconfig/icon.png" width=16/> | file-extensions="editorconfig" | [main@editorconfig/editorconfig-vscode](https://github.com/editorconfig/editorconfig-vscode/tree/e32b46f6e0a1ee53059675ed00e7513d7b096feb/)
138143
| Elm <img src="plugin/syntaxes/elm/icon.png" width=16/> | file-extensions="elm" | [main@elm-tooling/elm-language-client-vscode](https://github.com/elm-tooling/elm-language-client-vscode/tree/cc3a7c463a7af57639ee91d4717be1723a936156/)
139144
| Embedded Crystal <img src="plugin/syntaxes/crystal/icon.png" width=16/> | file-extensions="ecr" | [master@crystal-lang-tools/vscode-crystal-lang](https://github.com/crystal-lang-tools/vscode-crystal-lang/tree/9d85621bd72b76fb5f4c81dd8357a3e6e834f7ce/)

plugin/plugin.xml

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,107 @@
568568
<snippet name="TSV Example" path="syntaxes/csv/tsv.example.tsv" scopeName="text.tsv" />
569569
</extension>
570570

571+
<!-- ======================================== -->
572+
<!-- d/d: D -->
573+
<!-- ======================================== -->
574+
<extension point="org.eclipse.core.contenttype.contentTypes">
575+
<content-type id="extra-syntax-highlighting.d" name="D" base-type="extra-syntax-highlighting.basetype" priority="normal"
576+
file-extensions="d,di" />
577+
</extension>
578+
<extension point="org.eclipse.tm4e.registry.grammars">
579+
<grammar scopeName="source.d" path="syntaxes/d/d.tmLanguage.json" />
580+
<scopeNameContentTypeBinding scopeName="source.d" contentTypeId="extra-syntax-highlighting.d" />
581+
</extension>
582+
583+
<extension point="org.eclipse.tm4e.languageconfiguration.languageConfigurations">
584+
<languageConfiguration contentTypeId="extra-syntax-highlighting.d" path="syntaxes/d/d.language-configuration.json" />
585+
</extension>
586+
587+
<extension point="org.eclipse.ui.genericeditor.icons">
588+
<icon contentType="extra-syntax-highlighting.d" icon="syntaxes/d/icon.png"/>
589+
</extension>
590+
591+
<extension point="org.eclipse.tm4e.ui.snippets">
592+
<snippet name="D Example" path="syntaxes/d/d.example.d" scopeName="source.d" />
593+
</extension>
594+
595+
<!-- ======================================== -->
596+
<!-- d/d-injection: d-injection -->
597+
<!-- ======================================== -->
598+
<extension point="org.eclipse.core.contenttype.contentTypes">
599+
<content-type id="extra-syntax-highlighting.d-injection" name="d-injection" base-type="extra-syntax-highlighting.basetype" priority="normal"
600+
file-names="PREVENT_FILE_ASSOCIATION_INHERITANCE" />
601+
</extension>
602+
<extension point="org.eclipse.tm4e.registry.grammars">
603+
<grammar scopeName="markdown.d.codeblock" path="syntaxes/d/d-injection.tmLanguage.json" />
604+
<scopeNameContentTypeBinding scopeName="markdown.d.codeblock" contentTypeId="extra-syntax-highlighting.d-injection" />
605+
<injection scopeName="markdown.d.codeblock" injectTo="text.html.markdown" />
606+
</extension>
607+
608+
<extension point="org.eclipse.ui.genericeditor.icons">
609+
<icon contentType="extra-syntax-highlighting.d-injection" icon="syntaxes/d/icon.png"/>
610+
</extension>
611+
612+
<!-- ======================================== -->
613+
<!-- d/diet: Diet -->
614+
<!-- ======================================== -->
615+
<extension point="org.eclipse.core.contenttype.contentTypes">
616+
<content-type id="extra-syntax-highlighting.diet" name="Diet" base-type="extra-syntax-highlighting.basetype" priority="normal"
617+
file-extensions="dt" />
618+
</extension>
619+
<extension point="org.eclipse.tm4e.registry.grammars">
620+
<grammar scopeName="source.diet" path="syntaxes/d/diet.tmLanguage.json" />
621+
<scopeNameContentTypeBinding scopeName="source.diet" contentTypeId="extra-syntax-highlighting.diet" />
622+
</extension>
623+
624+
<extension point="org.eclipse.tm4e.languageconfiguration.languageConfigurations">
625+
<languageConfiguration contentTypeId="extra-syntax-highlighting.diet" path="syntaxes/d/diet.language-configuration.json" />
626+
</extension>
627+
628+
<extension point="org.eclipse.ui.genericeditor.icons">
629+
<icon contentType="extra-syntax-highlighting.diet" icon="syntaxes/d/icon.png"/>
630+
</extension>
631+
632+
<!-- ======================================== -->
633+
<!-- d/dml: DlangUI Markup Language -->
634+
<!-- ======================================== -->
635+
<extension point="org.eclipse.core.contenttype.contentTypes">
636+
<content-type id="extra-syntax-highlighting.dml" name="DlangUI Markup Language" base-type="extra-syntax-highlighting.basetype" priority="normal"
637+
file-extensions="dml" />
638+
</extension>
639+
<extension point="org.eclipse.tm4e.registry.grammars">
640+
<grammar scopeName="source.dml" path="syntaxes/d/dml.tmLanguage.json" />
641+
<scopeNameContentTypeBinding scopeName="source.dml" contentTypeId="extra-syntax-highlighting.dml" />
642+
</extension>
643+
644+
<extension point="org.eclipse.tm4e.languageconfiguration.languageConfigurations">
645+
<languageConfiguration contentTypeId="extra-syntax-highlighting.dml" path="syntaxes/d/dml.language-configuration.json" />
646+
</extension>
647+
648+
<extension point="org.eclipse.ui.genericeditor.icons">
649+
<icon contentType="extra-syntax-highlighting.dml" icon="syntaxes/d/icon.png"/>
650+
</extension>
651+
652+
<!-- ======================================== -->
653+
<!-- d/dscript: arsd.DScript -->
654+
<!-- ======================================== -->
655+
<extension point="org.eclipse.core.contenttype.contentTypes">
656+
<content-type id="extra-syntax-highlighting.dscript" name="arsd.DScript" base-type="extra-syntax-highlighting.basetype" priority="normal"
657+
file-extensions="ds,dscript" />
658+
</extension>
659+
<extension point="org.eclipse.tm4e.registry.grammars">
660+
<grammar scopeName="source.dscript" path="syntaxes/d/dscript.tmLanguage.json" />
661+
<scopeNameContentTypeBinding scopeName="source.dscript" contentTypeId="extra-syntax-highlighting.dscript" />
662+
</extension>
663+
664+
<extension point="org.eclipse.tm4e.languageconfiguration.languageConfigurations">
665+
<languageConfiguration contentTypeId="extra-syntax-highlighting.dscript" path="syntaxes/d/dscript.language-configuration.json" />
666+
</extension>
667+
668+
<extension point="org.eclipse.ui.genericeditor.icons">
669+
<icon contentType="extra-syntax-highlighting.dscript" icon="syntaxes/d/icon.png"/>
670+
</extension>
671+
571672
<!-- ======================================== -->
572673
<!-- d2/d2: d2 -->
573674
<!-- ======================================== -->

plugin/syntaxes/d/LICENSE.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2015 Jan Jurzitza
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"fileTypes": [],
3+
"injectionSelector": "L:text.html.markdown",
4+
"patterns": [
5+
{
6+
"include": "#d-code-block"
7+
}
8+
],
9+
"repository": {
10+
"d-code-block": {
11+
"begin": "(^|\\G)(\\s*)(\\`{3,}|~{3,})\\s*(?i:(d)(\\s+[^`~]*)?$)",
12+
"name": "markup.fenced_code.block.markdown",
13+
"end": "(^|\\G)(\\2|\\s{0,3})(\\3)\\s*$",
14+
"beginCaptures": {
15+
"3": {
16+
"name": "punctuation.definition.markdown"
17+
},
18+
"4": {
19+
"name": "fenced_code.block.language.markdown"
20+
},
21+
"5": {
22+
"name": "fenced_code.block.language.attributes.markdown"
23+
}
24+
},
25+
"endCaptures": {
26+
"3": {
27+
"name": "punctuation.definition.markdown"
28+
}
29+
},
30+
"patterns": [
31+
{
32+
"begin": "(^|\\G)(\\s*)(.*)",
33+
"while": "(^|\\G)(?!\\s*([`~]{3,})\\s*$)",
34+
"contentName": "meta.embedded.block.d",
35+
"patterns": [
36+
{
37+
"include": "source.d"
38+
}
39+
]
40+
}
41+
]
42+
}
43+
},
44+
"scopeName": "markdown.d.codeblock"
45+
}

plugin/syntaxes/d/d.example.d

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
import std.stdio;
2+
import std.algorithm;
3+
import std.range;
4+
import std.array;
5+
import std.parallelism;
6+
import std.datetime;
7+
import std.conv;
8+
9+
// ---------------------------
10+
// 1. Compile-Time Computation (CTFE)
11+
// ---------------------------
12+
enum fib10 = fib(10); // evaluated at compile time
13+
14+
int fib(int n) {
15+
return n <= 1 ? n : fib(n - 1) + fib(n - 2);
16+
}
17+
18+
// ---------------------------
19+
// 2. Templates + Constraints
20+
// ---------------------------
21+
T addIfNumeric(T)(T a, T b)
22+
if (isNumeric!T) {
23+
return a + b;
24+
}
25+
26+
// ---------------------------
27+
// 3. Struct with @safe + methods
28+
// ---------------------------
29+
@safe struct Point {
30+
double x, y;
31+
32+
double length() const {
33+
import std.math : sqrt;
34+
return sqrt(x * x + y * y);
35+
}
36+
}
37+
38+
// ---------------------------
39+
// 4. Mixins (code generation)
40+
// ---------------------------
41+
mixin template DebugPrint(T) {
42+
void debugPrint() const {
43+
writeln("Debug: ", this);
44+
}
45+
}
46+
47+
struct User {
48+
string name;
49+
int age;
50+
51+
mixin DebugPrint!User;
52+
}
53+
54+
// ---------------------------
55+
// 5. UFCS + Ranges + Functional style
56+
// ---------------------------
57+
void processData() {
58+
auto result =
59+
iota(1, 10) // range [1..9]
60+
.map!(x => x * x) // square
61+
.filter!(x => x % 2 == 0) // even
62+
.array; // materialize
63+
64+
writeln("Processed: ", result);
65+
}
66+
67+
// ---------------------------
68+
// 6. Parallelism
69+
// ---------------------------
70+
void parallelExample() {
71+
auto data = iota(1, 1_000_000).array;
72+
73+
// Parallel map
74+
auto squared = taskPool.parallel(data)
75+
.map!(x => x * x)
76+
.array;
77+
78+
writeln("Parallel sum: ", squared.sum);
79+
}
80+
81+
// ---------------------------
82+
// 7. Classes + OOP
83+
// ---------------------------
84+
class Animal {
85+
void speak() {
86+
writeln("Some sound");
87+
}
88+
}
89+
90+
class Dog : Animal {
91+
override void speak() {
92+
writeln("Woof");
93+
}
94+
}
95+
96+
// ---------------------------
97+
// 8. main()
98+
// ---------------------------
99+
void main() {
100+
writeln("CTFE fib(10): ", fib10);
101+
102+
// Type inference + templates
103+
auto sum = addIfNumeric(3, 4);
104+
writeln("Sum: ", sum);
105+
106+
// Struct usage
107+
Point p = Point(3, 4);
108+
writeln("Length: ", p.length());
109+
110+
// Mixins
111+
User u = User("Alice", 30);
112+
u.debugPrint();
113+
114+
// Functional pipelines
115+
processData();
116+
117+
// Parallel computation
118+
parallelExample();
119+
120+
// OOP
121+
Animal a = new Dog();
122+
a.speak();
123+
124+
// UFCS example
125+
auto text = 123.to!string().writeln; // chaining
126+
}

0 commit comments

Comments
 (0)