tree-sitter-shik 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +8 -0
- package/binding.gyp +35 -0
- package/bindings/node/binding.cc +19 -0
- package/bindings/node/binding_test.js +9 -0
- package/bindings/node/index.d.ts +27 -0
- package/bindings/node/index.js +11 -0
- package/grammar.js +213 -0
- package/package.json +54 -0
- package/queries/shik/highlights.scm +119 -0
- package/queries/shik/locals.scm +26 -0
- package/shik.tmLanguage.json +118 -0
- package/src/grammar.json +887 -0
- package/src/node-types.json +737 -0
- package/src/parser.c +7801 -0
- package/src/tree_sitter/alloc.h +54 -0
- package/src/tree_sitter/array.h +291 -0
- package/src/tree_sitter/parser.h +286 -0
- package/tree-sitter-shik.wasm +0 -0
- package/tree-sitter.json +41 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Maksim Iakovlev
|
|
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.
|
package/README.md
ADDED
package/binding.gyp
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"targets": [
|
|
3
|
+
{
|
|
4
|
+
"target_name": "tree_sitter_shik_binding",
|
|
5
|
+
"dependencies": [
|
|
6
|
+
"<!(node -p \"require('node-addon-api').targets\"):node_addon_api_except",
|
|
7
|
+
],
|
|
8
|
+
"include_dirs": [
|
|
9
|
+
"src",
|
|
10
|
+
],
|
|
11
|
+
"sources": [
|
|
12
|
+
"bindings/node/binding.cc",
|
|
13
|
+
"src/parser.c",
|
|
14
|
+
],
|
|
15
|
+
"variables": {
|
|
16
|
+
"has_scanner": "<!(node -p \"fs.existsSync('src/scanner.c')\")"
|
|
17
|
+
},
|
|
18
|
+
"conditions": [
|
|
19
|
+
["has_scanner=='true'", {
|
|
20
|
+
"sources+": ["src/scanner.c"],
|
|
21
|
+
}],
|
|
22
|
+
["OS!='win'", {
|
|
23
|
+
"cflags_c": [
|
|
24
|
+
"-std=c11",
|
|
25
|
+
],
|
|
26
|
+
}, { # OS == "win"
|
|
27
|
+
"cflags_c": [
|
|
28
|
+
"/std:c11",
|
|
29
|
+
"/utf-8",
|
|
30
|
+
],
|
|
31
|
+
}],
|
|
32
|
+
],
|
|
33
|
+
}
|
|
34
|
+
]
|
|
35
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
#include <napi.h>
|
|
2
|
+
|
|
3
|
+
typedef struct TSLanguage TSLanguage;
|
|
4
|
+
|
|
5
|
+
extern "C" TSLanguage *tree_sitter_shik();
|
|
6
|
+
|
|
7
|
+
// "tree-sitter", "language" hashed with BLAKE2
|
|
8
|
+
const napi_type_tag LANGUAGE_TYPE_TAG = {
|
|
9
|
+
0x8AF2E5212AD58ABF, 0xD5006CAD83ABBA16
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
Napi::Object Init(Napi::Env env, Napi::Object exports) {
|
|
13
|
+
auto language = Napi::External<TSLanguage>::New(env, tree_sitter_shik());
|
|
14
|
+
language.TypeTag(&LANGUAGE_TYPE_TAG);
|
|
15
|
+
exports["language"] = language;
|
|
16
|
+
return exports;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
NODE_API_MODULE(tree_sitter_shik_binding, Init)
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
type BaseNode = {
|
|
2
|
+
type: string;
|
|
3
|
+
named: boolean;
|
|
4
|
+
};
|
|
5
|
+
|
|
6
|
+
type ChildNode = {
|
|
7
|
+
multiple: boolean;
|
|
8
|
+
required: boolean;
|
|
9
|
+
types: BaseNode[];
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
type NodeInfo =
|
|
13
|
+
| (BaseNode & {
|
|
14
|
+
subtypes: BaseNode[];
|
|
15
|
+
})
|
|
16
|
+
| (BaseNode & {
|
|
17
|
+
fields: { [name: string]: ChildNode };
|
|
18
|
+
children: ChildNode[];
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
type Language = {
|
|
22
|
+
language: unknown;
|
|
23
|
+
nodeTypeInfo: NodeInfo[];
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
declare const language: Language;
|
|
27
|
+
export = language;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
const root = require("path").join(__dirname, "..", "..");
|
|
2
|
+
|
|
3
|
+
module.exports =
|
|
4
|
+
typeof process.versions.bun === "string"
|
|
5
|
+
// Support `bun build --compile` by being statically analyzable enough to find the .node file at build-time
|
|
6
|
+
? require(`../../prebuilds/${process.platform}-${process.arch}/tree-sitter-shik.node`)
|
|
7
|
+
: require("node-gyp-build")(root);
|
|
8
|
+
|
|
9
|
+
try {
|
|
10
|
+
module.exports.nodeTypeInfo = require("../../src/node-types.json");
|
|
11
|
+
} catch (_) {}
|
package/grammar.js
ADDED
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file scripting language
|
|
3
|
+
* @author pungy <max.yakovlev555@gmail.com>
|
|
4
|
+
* @license MIT
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* TreeSitter grammar
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
const ws = /[ \t]/;
|
|
13
|
+
const wsO = /[ \t]*/;
|
|
14
|
+
const wsM = /[ \t]+/;
|
|
15
|
+
const newline = /\r?\n/;
|
|
16
|
+
|
|
17
|
+
const PREC = {
|
|
18
|
+
PIPE: 1,
|
|
19
|
+
CHAIN: 2,
|
|
20
|
+
FLOW: 3,
|
|
21
|
+
APPLY: 4,
|
|
22
|
+
|
|
23
|
+
LITERAL: 1,
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
module.exports = grammar({
|
|
27
|
+
name: 'shik',
|
|
28
|
+
|
|
29
|
+
word: $ => $.identifier,
|
|
30
|
+
|
|
31
|
+
extras: $ => [
|
|
32
|
+
ws,
|
|
33
|
+
newline,
|
|
34
|
+
$.line_comment,
|
|
35
|
+
$.block_comment,
|
|
36
|
+
],
|
|
37
|
+
|
|
38
|
+
rules: {
|
|
39
|
+
program: $ => repeat($.statement),
|
|
40
|
+
|
|
41
|
+
statement: $ => seq($.expression, newline),
|
|
42
|
+
|
|
43
|
+
line_comment: $ => token(seq(
|
|
44
|
+
';',
|
|
45
|
+
/.*/
|
|
46
|
+
)),
|
|
47
|
+
|
|
48
|
+
block_comment: $ => token(seq(
|
|
49
|
+
'{*',
|
|
50
|
+
/[^*]*\*+([^}*][^*]*\*+)*/,
|
|
51
|
+
'}',
|
|
52
|
+
)),
|
|
53
|
+
|
|
54
|
+
expression: $ => choice($.flow_expression, $.chain_expression, $.pipe_expression, $.application, $.primary),
|
|
55
|
+
|
|
56
|
+
pipe_expression: $ => prec.left(PREC.PIPE, seq(
|
|
57
|
+
field('left', $.expression),
|
|
58
|
+
'$>',
|
|
59
|
+
field('right', $.expression),
|
|
60
|
+
)),
|
|
61
|
+
chain_expression: $ => prec.left(PREC.CHAIN, seq(
|
|
62
|
+
field('left', $.expression),
|
|
63
|
+
'$',
|
|
64
|
+
field('right', $.expression),
|
|
65
|
+
)),
|
|
66
|
+
|
|
67
|
+
flow_expression: $ => prec.left(PREC.FLOW, seq(
|
|
68
|
+
field('left', $.expression),
|
|
69
|
+
'#>',
|
|
70
|
+
field('right', $.expression),
|
|
71
|
+
)),
|
|
72
|
+
|
|
73
|
+
application: $ => prec.left(PREC.APPLY, seq(
|
|
74
|
+
field('fn', $.expression),
|
|
75
|
+
field('arg', $.primary),
|
|
76
|
+
)),
|
|
77
|
+
|
|
78
|
+
primary: $ => choice(
|
|
79
|
+
$.lambda,
|
|
80
|
+
$.let_expression,
|
|
81
|
+
$.match_expression,
|
|
82
|
+
$.list,
|
|
83
|
+
$.object,
|
|
84
|
+
$.literal,
|
|
85
|
+
$.identifier,
|
|
86
|
+
$.parenthesized,
|
|
87
|
+
$.block,
|
|
88
|
+
$.lazy,
|
|
89
|
+
),
|
|
90
|
+
|
|
91
|
+
parenthesized: $ => seq('(', $.expression, ')'),
|
|
92
|
+
block: $ => seq(
|
|
93
|
+
"'(",
|
|
94
|
+
repeat(seq($.expression, optional(newline))),
|
|
95
|
+
')'
|
|
96
|
+
),
|
|
97
|
+
lazy: $ => seq(
|
|
98
|
+
"#(",
|
|
99
|
+
repeat(seq($.expression, optional(newline))),
|
|
100
|
+
')'
|
|
101
|
+
),
|
|
102
|
+
|
|
103
|
+
list: $ => seq(
|
|
104
|
+
'[',
|
|
105
|
+
repeat($.primary),
|
|
106
|
+
']'
|
|
107
|
+
),
|
|
108
|
+
|
|
109
|
+
object: $ => seq(
|
|
110
|
+
'{',
|
|
111
|
+
repeat($.object_items),
|
|
112
|
+
'}'
|
|
113
|
+
),
|
|
114
|
+
object_items: $ => seq(
|
|
115
|
+
field('key', $.primary),
|
|
116
|
+
field('value', $.primary),
|
|
117
|
+
),
|
|
118
|
+
|
|
119
|
+
match_expression: $ => seq(
|
|
120
|
+
'match',
|
|
121
|
+
field('value', $.primary),
|
|
122
|
+
'{',
|
|
123
|
+
repeat($.match_arm),
|
|
124
|
+
'}'
|
|
125
|
+
),
|
|
126
|
+
match_arm: $ => seq(
|
|
127
|
+
field('pattern', choice(
|
|
128
|
+
$.match_pattern,
|
|
129
|
+
seq('#', field('name', $.identifier)),
|
|
130
|
+
)),
|
|
131
|
+
field('body', $.primary),
|
|
132
|
+
),
|
|
133
|
+
|
|
134
|
+
let_expression: $ => seq(
|
|
135
|
+
'let$',
|
|
136
|
+
field('name', $.let_pattern),
|
|
137
|
+
field('value', $.expression)
|
|
138
|
+
),
|
|
139
|
+
let_pattern: $ => choice($.identifier, $.let_list_pattern),
|
|
140
|
+
let_list_pattern: $ => seq(
|
|
141
|
+
'[',
|
|
142
|
+
repeat($.let_pattern),
|
|
143
|
+
field('rest', optional(seq('#', $.identifier))),
|
|
144
|
+
']',
|
|
145
|
+
),
|
|
146
|
+
|
|
147
|
+
lambda: $ => seq(
|
|
148
|
+
'fn',
|
|
149
|
+
'[',
|
|
150
|
+
field('arg', repeat($.match_pattern)),
|
|
151
|
+
field('rest', optional(seq('#', $.identifier))),
|
|
152
|
+
']',
|
|
153
|
+
field('body', $.expression),
|
|
154
|
+
),
|
|
155
|
+
match_pattern: $ => choice(
|
|
156
|
+
$.identifier,
|
|
157
|
+
$.literal,
|
|
158
|
+
$.match_list_pattern,
|
|
159
|
+
'_',
|
|
160
|
+
),
|
|
161
|
+
match_list_pattern: $ => seq(
|
|
162
|
+
'[',
|
|
163
|
+
repeat($.match_pattern),
|
|
164
|
+
optional(seq('#', $.identifier)),
|
|
165
|
+
']',
|
|
166
|
+
),
|
|
167
|
+
|
|
168
|
+
literal: $ => choice(
|
|
169
|
+
$.string,
|
|
170
|
+
$.number
|
|
171
|
+
),
|
|
172
|
+
|
|
173
|
+
string: $ => choice(
|
|
174
|
+
$.symbol_string,
|
|
175
|
+
$.quoted_string
|
|
176
|
+
),
|
|
177
|
+
|
|
178
|
+
symbol_string: $ => seq(
|
|
179
|
+
':',
|
|
180
|
+
$.symbol_string_content,
|
|
181
|
+
),
|
|
182
|
+
|
|
183
|
+
quoted_string: $ => seq(
|
|
184
|
+
'"',
|
|
185
|
+
repeat(choice(
|
|
186
|
+
$.string_content,
|
|
187
|
+
$.escape_sequence,
|
|
188
|
+
$.interpolation
|
|
189
|
+
)),
|
|
190
|
+
'"'
|
|
191
|
+
),
|
|
192
|
+
string_content: $ => token.immediate(prec(1, /[^"\\{]+/)),
|
|
193
|
+
symbol_string_content: $ => token.immediate(prec(1, /[^\s\t\n\(\{\[\]\}\)]+/)),
|
|
194
|
+
escape_sequence: $ => token.immediate(choice(
|
|
195
|
+
/\\x[0-9a-fA-F]{2}/,
|
|
196
|
+
/\\u\{[0-9a-fA-F]+\}/,
|
|
197
|
+
/\\./,
|
|
198
|
+
)),
|
|
199
|
+
interpolation: $ => seq(
|
|
200
|
+
'{',
|
|
201
|
+
$.expression,
|
|
202
|
+
'}'
|
|
203
|
+
),
|
|
204
|
+
|
|
205
|
+
number: $ => prec.dynamic(1, token(seq(
|
|
206
|
+
optional('-'),
|
|
207
|
+
/\d+/,
|
|
208
|
+
optional(seq('.', /\d+/))
|
|
209
|
+
))),
|
|
210
|
+
|
|
211
|
+
identifier: $ => /[\p{L}\p{N}!@%^&*\-_=+|?<>$.][\p{L}\p{N}!@#%^&*\-_=+'|?<>$.]*/u,
|
|
212
|
+
}
|
|
213
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "tree-sitter-shik",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "scripting language",
|
|
5
|
+
"repository": "https://github.com/PunGy/shik-treesitter",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"author": {
|
|
8
|
+
"name": "pungy",
|
|
9
|
+
"email": "max.yakovlev555@gmail.com",
|
|
10
|
+
"url": "https://pungy.me/"
|
|
11
|
+
},
|
|
12
|
+
"main": "bindings/node",
|
|
13
|
+
"types": "bindings/node",
|
|
14
|
+
"keywords": [
|
|
15
|
+
"incremental",
|
|
16
|
+
"parsing",
|
|
17
|
+
"tree-sitter",
|
|
18
|
+
"shik"
|
|
19
|
+
],
|
|
20
|
+
"files": [
|
|
21
|
+
"grammar.js",
|
|
22
|
+
"tree-sitter.json",
|
|
23
|
+
"binding.gyp",
|
|
24
|
+
"prebuilds/**",
|
|
25
|
+
"bindings/node/*",
|
|
26
|
+
"queries/*",
|
|
27
|
+
"src/**",
|
|
28
|
+
"*.wasm",
|
|
29
|
+
"shik.tmLanguage.json"
|
|
30
|
+
],
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"node-addon-api": "^8.5.0",
|
|
33
|
+
"node-gyp-build": "^4.8.4"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"prebuildify": "^6.0.1",
|
|
37
|
+
"tree-sitter": "^0.22.4",
|
|
38
|
+
"tree-sitter-cli": "^0.25.10"
|
|
39
|
+
},
|
|
40
|
+
"peerDependencies": {
|
|
41
|
+
"tree-sitter": "^0.22.4"
|
|
42
|
+
},
|
|
43
|
+
"peerDependenciesMeta": {
|
|
44
|
+
"tree-sitter": {
|
|
45
|
+
"optional": true
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
"scripts": {
|
|
49
|
+
"install": "node-gyp-build || true",
|
|
50
|
+
"prestart": "tree-sitter build --wasm",
|
|
51
|
+
"start": "tree-sitter playground",
|
|
52
|
+
"test": "node --test bindings/node/*_test.js"
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
; Comments
|
|
2
|
+
(line_comment) @comment
|
|
3
|
+
(block_comment) @comment
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
; === Punctuation ===
|
|
7
|
+
"[" @punctuation.bracket
|
|
8
|
+
"]" @punctuation.bracket
|
|
9
|
+
"{" @punctuation.bracket
|
|
10
|
+
"}" @punctuation.bracket
|
|
11
|
+
"(" @punctuation.bracket
|
|
12
|
+
")" @punctuation.bracket
|
|
13
|
+
"'(" @punctuation.special
|
|
14
|
+
"#(" @punctuation.special
|
|
15
|
+
(interpolation
|
|
16
|
+
"{" @punctuation.special
|
|
17
|
+
"}" @punctuation.special) @embedded
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
; === Binary operators ===
|
|
21
|
+
"$>" @keyword
|
|
22
|
+
"$" @keyword
|
|
23
|
+
"#>" @keyword
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
; === Literals ===
|
|
27
|
+
(number) @number
|
|
28
|
+
(quoted_string) @string
|
|
29
|
+
(escape_sequence) @string.escape
|
|
30
|
+
(symbol_string ":" @punctuation.special)
|
|
31
|
+
(symbol_string_content) @string
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
; === Built-in functions ===
|
|
35
|
+
; Module-qualified names (string.upper, list.map, file.read, etc.)
|
|
36
|
+
; These come before generic @function captures so they take priority.
|
|
37
|
+
((identifier) @function.builtin
|
|
38
|
+
(#match? @function.builtin "^(string|list|object|file|shell|number|process|fn|var)\\."))
|
|
39
|
+
|
|
40
|
+
; Common standalone built-ins
|
|
41
|
+
((identifier) @function.builtin
|
|
42
|
+
(#any-of? @function.builtin
|
|
43
|
+
"print" "bool" "string" "at" "iterate" "or?" "invoke"))
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
; === Function position highlighting ===
|
|
47
|
+
(application
|
|
48
|
+
fn: (expression
|
|
49
|
+
(primary
|
|
50
|
+
(identifier) @function)))
|
|
51
|
+
|
|
52
|
+
(pipe_expression
|
|
53
|
+
right: (expression
|
|
54
|
+
(primary
|
|
55
|
+
(identifier) @function)))
|
|
56
|
+
|
|
57
|
+
(chain_expression
|
|
58
|
+
left: (expression
|
|
59
|
+
(primary
|
|
60
|
+
(identifier) @function)))
|
|
61
|
+
|
|
62
|
+
(flow_expression
|
|
63
|
+
left: (expression
|
|
64
|
+
(primary
|
|
65
|
+
(identifier) @function))
|
|
66
|
+
right: (expression
|
|
67
|
+
(primary
|
|
68
|
+
(identifier) @function)))
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
; === Object keys ===
|
|
72
|
+
(object_items
|
|
73
|
+
key: (primary) @property)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
; === Lambda / let parameters ===
|
|
77
|
+
(lambda
|
|
78
|
+
(match_pattern (identifier) @variable.parameter))
|
|
79
|
+
(lambda
|
|
80
|
+
rest: (identifier) @variable.parameter)
|
|
81
|
+
(match_pattern (match_list_pattern (match_pattern (identifier) @variable.parameter)))
|
|
82
|
+
|
|
83
|
+
(let_pattern (identifier) @variable.parameter)
|
|
84
|
+
(let_list_pattern
|
|
85
|
+
rest: (identifier) @variable.parameter)
|
|
86
|
+
(let_pattern (let_list_pattern (let_pattern (identifier) @variable.parameter)))
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
; === Keywords ===
|
|
90
|
+
"fn" @keyword
|
|
91
|
+
"let$" @keyword
|
|
92
|
+
"match" @keyword
|
|
93
|
+
|
|
94
|
+
((identifier) @keyword
|
|
95
|
+
(#any-of? @keyword
|
|
96
|
+
"if"
|
|
97
|
+
"let" "set" "set+" "set-"
|
|
98
|
+
"while"))
|
|
99
|
+
|
|
100
|
+
; The '#' prefix in rest params and named wildcards: #rest, #name
|
|
101
|
+
"#" @punctuation.special
|
|
102
|
+
|
|
103
|
+
; Named wildcard in match patterns: #name
|
|
104
|
+
(match_arm
|
|
105
|
+
name: (identifier) @variable.parameter)
|
|
106
|
+
|
|
107
|
+
; Rest identifier in match list patterns [a b #rest]
|
|
108
|
+
; (bare identifier child, pattern identifiers are wrapped in match_pattern)
|
|
109
|
+
(match_list_pattern (identifier) @variable.parameter)
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
; === Constants ===
|
|
113
|
+
((identifier) @boolean
|
|
114
|
+
(#any-of? @boolean "true" "false"))
|
|
115
|
+
|
|
116
|
+
((identifier) @constant.builtin
|
|
117
|
+
(#any-of? @constant.builtin "null"))
|
|
118
|
+
|
|
119
|
+
"_" @constant.builtin
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
; Scopes — each lambda/block/lazy introduces a new local scope
|
|
2
|
+
(lambda) @local.scope
|
|
3
|
+
(block) @local.scope
|
|
4
|
+
(lazy) @local.scope
|
|
5
|
+
|
|
6
|
+
; Definitions — lambda parameters
|
|
7
|
+
(lambda
|
|
8
|
+
(match_pattern (identifier) @local.definition))
|
|
9
|
+
(lambda
|
|
10
|
+
rest: (identifier) @local.definition)
|
|
11
|
+
(match_list_pattern (identifier) @local.definition)
|
|
12
|
+
|
|
13
|
+
; Definitions — let bindings
|
|
14
|
+
(let_expression
|
|
15
|
+
name: (let_pattern (identifier) @local.definition))
|
|
16
|
+
(let_list_pattern
|
|
17
|
+
rest: (identifier) @local.definition)
|
|
18
|
+
(let_pattern
|
|
19
|
+
(let_list_pattern (let_pattern (identifier) @local.definition)))
|
|
20
|
+
|
|
21
|
+
; Definitions — match arm named wildcards (#name)
|
|
22
|
+
(match_arm
|
|
23
|
+
name: (identifier) @local.definition)
|
|
24
|
+
|
|
25
|
+
; References — all other identifier usages
|
|
26
|
+
(identifier) @local.reference
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
|
|
3
|
+
"name": "Shik",
|
|
4
|
+
"scopeName": "source.shik",
|
|
5
|
+
"fileTypes": ["shk"],
|
|
6
|
+
"patterns": [
|
|
7
|
+
{ "include": "#block-comment" },
|
|
8
|
+
{ "include": "#line-comment" },
|
|
9
|
+
{ "include": "#quoted-string" },
|
|
10
|
+
{ "include": "#symbol-string" },
|
|
11
|
+
{ "include": "#number" },
|
|
12
|
+
{ "include": "#keyword" },
|
|
13
|
+
{ "include": "#operator" },
|
|
14
|
+
{ "include": "#special-bracket" },
|
|
15
|
+
{ "include": "#constant" }
|
|
16
|
+
],
|
|
17
|
+
"repository": {
|
|
18
|
+
"block-comment": {
|
|
19
|
+
"name": "comment.block.shik",
|
|
20
|
+
"begin": "\\{\\*",
|
|
21
|
+
"end": "\\*\\}",
|
|
22
|
+
"beginCaptures": { "0": { "name": "punctuation.definition.comment.shik" } },
|
|
23
|
+
"endCaptures": { "0": { "name": "punctuation.definition.comment.shik" } }
|
|
24
|
+
},
|
|
25
|
+
"line-comment": {
|
|
26
|
+
"name": "comment.line.shik",
|
|
27
|
+
"match": ";.*$"
|
|
28
|
+
},
|
|
29
|
+
"quoted-string": {
|
|
30
|
+
"name": "string.quoted.double.shik",
|
|
31
|
+
"begin": "\"",
|
|
32
|
+
"end": "\"",
|
|
33
|
+
"beginCaptures": { "0": { "name": "punctuation.definition.string.begin.shik" } },
|
|
34
|
+
"endCaptures": { "0": { "name": "punctuation.definition.string.end.shik" } },
|
|
35
|
+
"patterns": [
|
|
36
|
+
{ "include": "#escape-sequence" },
|
|
37
|
+
{ "include": "#interpolation" }
|
|
38
|
+
]
|
|
39
|
+
},
|
|
40
|
+
"escape-sequence": {
|
|
41
|
+
"name": "constant.character.escape.shik",
|
|
42
|
+
"match": "\\\\(?:x[0-9a-fA-F]{2}|u\\{[0-9a-fA-F]+\\}|.)"
|
|
43
|
+
},
|
|
44
|
+
"interpolation": {
|
|
45
|
+
"name": "meta.embedded.line.shik",
|
|
46
|
+
"contentName": "source.shik",
|
|
47
|
+
"begin": "\\{",
|
|
48
|
+
"end": "\\}",
|
|
49
|
+
"beginCaptures": { "0": { "name": "punctuation.section.embedded.begin.shik" } },
|
|
50
|
+
"endCaptures": { "0": { "name": "punctuation.section.embedded.end.shik" } },
|
|
51
|
+
"patterns": [{ "include": "$self" }]
|
|
52
|
+
},
|
|
53
|
+
"symbol-string": {
|
|
54
|
+
"name": "string.unquoted.shik",
|
|
55
|
+
"match": ":[^\\s\\t\\n(){}\\[\\]]+"
|
|
56
|
+
},
|
|
57
|
+
"number": {
|
|
58
|
+
"name": "constant.numeric.shik",
|
|
59
|
+
"match": "-?\\d+(?:\\.\\d+)?"
|
|
60
|
+
},
|
|
61
|
+
"keyword": {
|
|
62
|
+
"patterns": [
|
|
63
|
+
{
|
|
64
|
+
"comment": "let$ and set+/set- before their bare counterparts",
|
|
65
|
+
"name": "keyword.other.shik",
|
|
66
|
+
"match": "(?<![A-Za-z0-9!@%^&*\\-_=+|?<>$.#'])(?:let\\$|set[+\\-])(?![A-Za-z0-9!@%^&*\\-_=+|?<>$.#'])"
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
"name": "keyword.other.function.shik",
|
|
70
|
+
"match": "(?<![A-Za-z0-9!@%^&*\\-_=+|?<>$.#'])fn(?![A-Za-z0-9!@%^&*\\-_=+|?<>$.#'])"
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
"name": "keyword.control.shik",
|
|
74
|
+
"match": "(?<![A-Za-z0-9!@%^&*\\-_=+|?<>$.#'])(?:if|while|match)(?![A-Za-z0-9!@%^&*\\-_=+|?<>$.#'])"
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
"name": "keyword.other.shik",
|
|
78
|
+
"match": "(?<![A-Za-z0-9!@%^&*\\-_=+|?<>$.#'])(?:let|set)(?![A-Za-z0-9!@%^&*\\-_=+|?<>$.#'])"
|
|
79
|
+
}
|
|
80
|
+
]
|
|
81
|
+
},
|
|
82
|
+
"operator": {
|
|
83
|
+
"patterns": [
|
|
84
|
+
{
|
|
85
|
+
"name": "keyword.operator.shik",
|
|
86
|
+
"match": "\\$>|#>"
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
"comment": "$ as chain operator — only valid surrounded by whitespace",
|
|
90
|
+
"name": "keyword.operator.shik",
|
|
91
|
+
"match": "(?<=\\s)\\$(?=\\s|$)"
|
|
92
|
+
}
|
|
93
|
+
]
|
|
94
|
+
},
|
|
95
|
+
"special-bracket": {
|
|
96
|
+
"patterns": [
|
|
97
|
+
{ "name": "punctuation.section.block.shik", "match": "'\\(" },
|
|
98
|
+
{ "name": "punctuation.section.lazy.shik", "match": "#\\(" }
|
|
99
|
+
]
|
|
100
|
+
},
|
|
101
|
+
"constant": {
|
|
102
|
+
"patterns": [
|
|
103
|
+
{
|
|
104
|
+
"name": "constant.language.boolean.shik",
|
|
105
|
+
"match": "(?<![A-Za-z0-9!@%^&*\\-_=+|?<>$.#'])(?:true|false)(?![A-Za-z0-9!@%^&*\\-_=+|?<>$.#'])"
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
"name": "constant.language.null.shik",
|
|
109
|
+
"match": "(?<![A-Za-z0-9!@%^&*\\-_=+|?<>$.#'])null(?![A-Za-z0-9!@%^&*\\-_=+|?<>$.#'])"
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
"name": "constant.language.wildcard.shik",
|
|
113
|
+
"match": "(?<![A-Za-z0-9!@%^&*\\-_=+|?<>$.#'])_(?![A-Za-z0-9!@%^&*\\-_=+|?<>$.#'])"
|
|
114
|
+
}
|
|
115
|
+
]
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|