Skip to content

Commit 3c9e892

Browse files
committed
update site to kdlv2
1 parent a79d041 commit 3c9e892

14 files changed

+615
-543
lines changed

.eleventy.js

Lines changed: 0 additions & 34 deletions
This file was deleted.

.eleventy.mjs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { createHighlighter } from "shiki";
2+
import path from "node:path";
3+
import { readFile } from "node:fs/promises";
4+
5+
export default function (eleventyConfig) {
6+
eleventyConfig.addPassthroughCopy("src/CNAME");
7+
eleventyConfig.addMarkdownHighlighter(shikiHighlight);
8+
9+
return {
10+
dir: {
11+
input: "src",
12+
output: "docs",
13+
},
14+
};
15+
};
16+
17+
const kdlGrammar = JSON.parse(await readFile(path.join(process.cwd(), "kdl.tmLanguage.json"), "utf8"));
18+
19+
const highlighter = await createHighlighter({
20+
themes: ["nord"],
21+
langs: [
22+
{
23+
name: "kdl",
24+
scopeName: "source.kdl",
25+
...kdlGrammar
26+
},
27+
],
28+
});
29+
30+
function shikiHighlight(code, lang) {
31+
return highlighter.codeToHtml(code, { lang, theme: "nord" });
32+
}

highlight_worker.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,22 @@ async function shiki_highlight(code, lang) {
1313
},
1414
],
1515
});
16-
return highlighter.codeToHtml(code, lang);
16+
console.log("highlighting...");
17+
const ret = highlighter.codeToHtml(code, lang);
18+
console.log("highlighted!");
19+
return ret;
1720
}
1821

1922
parentPort.addListener("message", async ({ signal, port, args }) => {
2023
// This is the async function that we want to run "synchronously"
2124
const result = await shiki_highlight(...args);
2225

2326
// Post the result to the main thread before unlocking "signal"
27+
console.log("posting result...");
2428
port.postMessage({ result });
29+
console.log("posted result");
2530
port.close();
31+
console.log("port closed");
2632

2733
// Change the value of signal[0] to 1
2834
Atomics.store(signal, 0, 1);

kdl.tmLanguage.json

Lines changed: 66 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
{
22
"$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
33
"comment": "Some of these patterns are taken straight from rust-analyzer: https://github.com/rust-lang/vscode-rust/blob/master/rust-analyzer/editors/code/rust.tmGrammar.json. Some was also taken from https://github.com/arm32x/vscode-sdlang/blob/master/syntaxes/sdlang.tmLanguage.json",
4-
"name": "KDL",
4+
"name": "kdl",
55
"patterns": [
6+
{
7+
"include": "#forbidden_ident"
8+
},
69
{
710
"include": "#null"
811
},
912
{
1013
"include": "#boolean"
1114
},
15+
{
16+
"include": "#float_keyword"
17+
},
1218
{
1319
"include": "#float_fraction"
1420
},
@@ -28,10 +34,13 @@
2834
"include": "#binary"
2935
},
3036
{
31-
"include": "#raw-strings"
37+
"include": "#raw-string"
38+
},
39+
{
40+
"include": "#string_multi_line"
3241
},
3342
{
34-
"include": "#strings"
43+
"include": "#string_single_line"
3544
},
3645
{
3746
"include": "#block_comment"
@@ -45,6 +54,9 @@
4554
{
4655
"include": "#slashdash_comment"
4756
},
57+
{
58+
"include": "#slashdash_node_with_children_comment"
59+
},
4860
{
4961
"include": "#slashdash_node_comment"
5062
},
@@ -56,6 +68,9 @@
5668
},
5769
{
5870
"include": "#node_name"
71+
},
72+
{
73+
"include": "#ident_string"
5974
}
6075
],
6176
"repository": {
@@ -77,54 +92,77 @@
7792
"hexadecimal": {
7893
"comment": "Integer literal (hexadecimal)",
7994
"name": "constant.numeric.integer.hexadecimal.rust",
80-
"match": "\\b0x[a-fA-F0-9_]+\\b"
95+
"match": "\\b0x[a-fA-F0-9][a-fA-F0-9_]*\\b"
8196
},
8297
"octal": {
8398
"comment": "Integer literal (octal)",
8499
"name": "constant.numeric.integer.octal.rust",
85-
"match": "\\b0o[0-7_]+\\b"
100+
"match": "\\b0o[0-7][0-7_]*\\b"
86101
},
87102
"binary": {
88103
"comment": "Integer literal (binary)",
89104
"name": "constant.numeric.integer.binary.rust",
90-
"match": "\\b0b[01_]+\\b"
105+
"match": "\\b0b[01][01_]*\\b"
106+
},
107+
"forbidden_ident": {
108+
"name": "invalid.illegal.kdl.bad-ident",
109+
"match": "(?<!#)(?:true|false|null|nan|[-]?inf)"
91110
},
92111
"node_name": {
93112
"name": "entity.name.tag",
94-
"match": "(?![\\\\{\\}<>;\\[\\]\\=,])[\\w\\-_~!@#\\$%^&*+|/.\\(\\)]+"
113+
"match": "((?<={|;)|^)\\s*(?![/\\\\{\\}#;\\[\\]\\=])[<>:\\w\\-_~,'`!\\?@\\$%^&*+|.\\(\\)]+\\d*[<>:\\w\\-_~,'`!\\?@\\$%^&*+|.\\(\\)]*"
95114
},
96115
"attribute": {
97116
"name": "entity.other.attribute-name.kdl",
98-
"match": "(?![\\\\{\\}<>;\\[\\]\\=,])[\\w\\-_~!@#\\$%^&*+|/.]+(=)",
117+
"match": "(?![/\\\\{\\}#;\\[\\]\\=])[<>:\\w\\-_~,'`!\\?@\\$%^&*+|.\\(\\)]+\\d*[<>:\\w\\-_~,'`!\\?@\\$%^&*+|.\\(\\)]*(=)",
99118
"captures": {
100119
"1": {
101120
"name": "punctuation.separator.key-value.kdl"
102121
}
103122
}
104123
},
124+
"ident_string": {
125+
"name": "string.unquoted",
126+
"match": "(?![/\\\\{\\}#;\\[\\]\\=])[<>:\\w\\-_~,'`!\\?@\\$%^&*+|.\\(\\)]+\\d*[<>:\\w\\-_~,'`!\\?@\\$%^&*+|.\\(\\)]*"
127+
},
128+
"float_keyword": {
129+
"name": "constant.language.other.kdl",
130+
"match": "#nan|#inf|#-inf"
131+
},
105132
"null": {
106133
"name": "constant.language.null.kdl",
107-
"match": "\\bnull\\b"
134+
"match": "#null"
108135
},
109136
"boolean": {
110137
"name": "constant.language.boolean.kdl",
111-
"match": "\\b(true|false)\\b"
138+
"match": "#true|#false"
112139
},
113-
"strings": {
140+
"string_single_line": {
114141
"name": "string.quoted.double.kdl",
115142
"begin": "\"",
116143
"end": "\"",
117144
"patterns": [
118145
{
119146
"name": "constant.character.escape.kdl",
120-
"match": "\\\\(:?[nrtbf\\\\\"]|u\\{[a-fA-F0-9]{1,6}\\})"
147+
"match": "\\\\(:?[nrtbfs\\\\\"]|u\\{[a-fA-F0-9]{1,6}\\})"
121148
}
122149
]
123150
},
124-
"raw-strings": {
125-
"name": "string.quoted.double.raw.kdl",
126-
"begin": "b?r(#*)\"",
127-
"end": "\"\\1"
151+
"string_multi_line": {
152+
"name": "string.quoted.triple.kdl",
153+
"begin": "\"\"\"",
154+
"end": "\"\"\"",
155+
"patterns": [
156+
{
157+
"name": "constant.character.escape.kdl",
158+
"match": "\\\\(:?[nrtbfs\\\\\"]|u\\{[a-fA-F0-9]{1,6}\\})"
159+
}
160+
]
161+
},
162+
"raw-string": {
163+
"name": "string.quoted.other.raw.kdl",
164+
"begin": "(#+)(\"{3,1})",
165+
"end": "\\2\\1"
128166
},
129167
"block_doc_comment": {
130168
"comment": "Block documentation comment",
@@ -156,26 +194,32 @@
156194
},
157195
"line_comment": {
158196
"comment": "Single-line comment",
159-
"name": "comment.line.double-slash.rust",
197+
"name": "comment.line.double-slash.kdl",
160198
"begin": "//",
161199
"end": "$"
162200
},
163201
"slashdash_comment": {
164-
"name": "comment.line.double-slash",
202+
"name": "comment.block.slashdash.kdl",
165203
"comment": "Slashdash inline comment",
166204
"begin": "(?<!^)/-",
167205
"end": "\\s"
168206
},
169207
"slashdash_node_comment": {
170-
"name": "comment.block",
208+
"name": "comment.block.slashdash.kdl",
171209
"comment": "Slashdash node comment",
172210
"begin": "(?<=^)/-",
173-
"end": "}"
211+
"end": "(?:;|(?<!\\\\)$)"
212+
},
213+
"slashdash_node_with_children_comment": {
214+
"name": "comment.block.slashdash.kdl",
215+
"comment": "Slashdash node comment",
216+
"begin": "(?<=^)/-[^{]+{",
217+
"end": "\\}"
174218
},
175219
"slashdash_block_comment": {
176-
"name": "comment.block",
220+
"name": "comment.block.slashdash.kdl",
177221
"comment": "Slashdash block comment",
178-
"begin": "/-{",
222+
"begin": "/-(?:\\s*){",
179223
"end": "}"
180224
}
181225
},

0 commit comments

Comments
 (0)