@willbooster/tree-sitter-go 5.0.0 → 6.1.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/README.md +8 -7
- package/grammar.js +19 -3
- package/package.json +17 -20
- package/queries/highlights.scm +56 -0
- package/src/node-types.json +14 -2
- package/tree-sitter-go.wasm +0 -0
- package/tree-sitter.json +1 -1
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
[](https://github.com/WillBooster/tree-sitter-go/actions/workflows/test.yml)
|
|
6
6
|
[](https://github.com/WillBooster/tree-sitter-go/actions/workflows/test-rust.yml)
|
|
7
7
|
[](https://github.com/semantic-release/semantic-release)
|
|
8
|
-
[](https://github.com/WillBooster/shared/tree/main/packages/wbfy)
|
|
9
9
|
[](https://crates.io/crates/willbooster-tree-sitter-go)
|
|
10
10
|
|
|
11
11
|
Go grammar for [tree-sitter](https://github.com/tree-sitter/tree-sitter), forked from
|
|
@@ -14,16 +14,17 @@ to its authors and contributors. This is not an official release of that project
|
|
|
14
14
|
|
|
15
15
|
This fork extends upstream's version 0.25.0 grammar with method type parameters and generates the parser with the
|
|
16
16
|
[WillBooster/tree-sitter](https://github.com/WillBooster/tree-sitter) generator. The parser carries that fork's own ABI
|
|
17
|
-
number (`
|
|
17
|
+
number (`0x5742000b`), so it loads only with the WillBooster runtime, version 15.0.0 or later within 15.x
|
|
18
18
|
(`willbooster-tree-sitter`, `@willbooster/web-tree-sitter`), and not with upstream's tree-sitter.
|
|
19
19
|
|
|
20
20
|
## Usage
|
|
21
21
|
|
|
22
22
|
The npm package ships `tree-sitter-go.wasm` for
|
|
23
|
-
[@willbooster/web-tree-sitter](https://www.npmjs.com/package/@willbooster/web-tree-sitter) version
|
|
23
|
+
[@willbooster/web-tree-sitter](https://www.npmjs.com/package/@willbooster/web-tree-sitter) version 15.0.0 or later within 15.x, which runs in Node.js, Bun, browsers, and Cloudflare Workers. In Node.js and Bun, load the grammar from its path:
|
|
24
24
|
|
|
25
25
|
```js
|
|
26
26
|
import { fileURLToPath } from 'node:url';
|
|
27
|
+
|
|
27
28
|
import { Language, Parser } from '@willbooster/web-tree-sitter';
|
|
28
29
|
|
|
29
30
|
await Parser.init();
|
|
@@ -36,9 +37,9 @@ const tree = parser.parse('package main\n\nfunc main() {}\n');
|
|
|
36
37
|
In browsers, serve both `.wasm` files and load them by URL (the example uses Vite's `?url` imports):
|
|
37
38
|
|
|
38
39
|
```js
|
|
40
|
+
import goUrl from '@willbooster/tree-sitter-go/tree-sitter-go.wasm?url';
|
|
39
41
|
import { Language, Parser } from '@willbooster/web-tree-sitter';
|
|
40
42
|
import runtimeUrl from '@willbooster/web-tree-sitter/web-tree-sitter.wasm?url';
|
|
41
|
-
import goUrl from '@willbooster/tree-sitter-go/tree-sitter-go.wasm?url';
|
|
42
43
|
|
|
43
44
|
await Parser.init({ locateFile: () => runtimeUrl });
|
|
44
45
|
const parser = new Parser();
|
|
@@ -49,9 +50,9 @@ Cloudflare Workers do not allow compiling Wasm at run time, so import both `.was
|
|
|
49
50
|
Node.js compatibility:
|
|
50
51
|
|
|
51
52
|
```js
|
|
53
|
+
import go from '@willbooster/tree-sitter-go/tree-sitter-go.wasm';
|
|
52
54
|
import { Language, Parser } from '@willbooster/web-tree-sitter';
|
|
53
55
|
import runtime from '@willbooster/web-tree-sitter/web-tree-sitter.wasm';
|
|
54
|
-
import go from '@willbooster/tree-sitter-go/tree-sitter-go.wasm';
|
|
55
56
|
|
|
56
57
|
await Parser.init({ wasmModule: runtime });
|
|
57
58
|
const parser = new Parser();
|
|
@@ -66,8 +67,8 @@ fuzzed with:
|
|
|
66
67
|
|
|
67
68
|
```toml
|
|
68
69
|
[dependencies]
|
|
69
|
-
tree-sitter = { package = "willbooster-tree-sitter", version = "
|
|
70
|
-
tree-sitter-go = { package = "willbooster-tree-sitter-go", version = "
|
|
70
|
+
tree-sitter = { package = "willbooster-tree-sitter", version = "15.0.0" }
|
|
71
|
+
tree-sitter-go = { package = "willbooster-tree-sitter-go", version = "6" }
|
|
71
72
|
```
|
|
72
73
|
|
|
73
74
|
```rust
|
package/grammar.js
CHANGED
|
@@ -63,6 +63,7 @@ const hexFloatLiteral = seq('0', choice('x', 'X'), hexMantissa, hexExponent);
|
|
|
63
63
|
const floatLiteral = choice(decimalFloatLiteral, hexFloatLiteral);
|
|
64
64
|
|
|
65
65
|
const imaginaryLiteral = seq(choice(decimalDigits, intLiteral, floatLiteral), 'i');
|
|
66
|
+
const formatArgumentIndex = /\[0*[1-9][0-9]*\]/;
|
|
66
67
|
|
|
67
68
|
module.exports = grammar({
|
|
68
69
|
name: 'go',
|
|
@@ -886,19 +887,34 @@ module.exports = grammar({
|
|
|
886
887
|
|
|
887
888
|
raw_string_literal: $ => seq(
|
|
888
889
|
'`',
|
|
889
|
-
|
|
890
|
-
|
|
890
|
+
repeat(choice(
|
|
891
|
+
alias(token.immediate(prec(1, /[^`%]+/)), $.raw_string_literal_content),
|
|
892
|
+
alias(token.immediate('%'), $.raw_string_literal_content),
|
|
893
|
+
$.format_specifier,
|
|
894
|
+
)),
|
|
895
|
+
token.immediate('`'),
|
|
891
896
|
),
|
|
892
897
|
|
|
893
898
|
interpreted_string_literal: $ => seq(
|
|
894
899
|
'"',
|
|
895
900
|
repeat(choice(
|
|
896
|
-
alias(token.immediate(prec(1, /[^"\n
|
|
901
|
+
alias(token.immediate(prec(1, /[^"\n\\%]+/)), $.interpreted_string_literal_content),
|
|
902
|
+
alias(token.immediate('%'), $.interpreted_string_literal_content),
|
|
903
|
+
$.format_specifier,
|
|
897
904
|
$.escape_sequence,
|
|
898
905
|
)),
|
|
899
906
|
token.immediate('"'),
|
|
900
907
|
),
|
|
901
908
|
|
|
909
|
+
format_specifier: _ => token.immediate(prec(2, seq(
|
|
910
|
+
'%',
|
|
911
|
+
/[+#0 -]*/,
|
|
912
|
+
optional(choice(/[0-9]+/, seq(optional(formatArgumentIndex), '*'))),
|
|
913
|
+
optional(seq('.', choice(/[0-9]*/, seq(optional(formatArgumentIndex), '*')))),
|
|
914
|
+
optional(formatArgumentIndex),
|
|
915
|
+
/[vTtbcdoOqxXUeEfFgGspw%]/,
|
|
916
|
+
))),
|
|
917
|
+
|
|
902
918
|
escape_sequence: _ => token.immediate(seq(
|
|
903
919
|
'\\',
|
|
904
920
|
choice(
|
package/package.json
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@willbooster/tree-sitter-go",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.1.0",
|
|
4
4
|
"description": "Go grammar for tree-sitter",
|
|
5
5
|
"keywords": [
|
|
6
|
+
"go",
|
|
6
7
|
"incremental",
|
|
7
8
|
"parsing",
|
|
8
|
-
"tree-sitter"
|
|
9
|
-
"go"
|
|
9
|
+
"tree-sitter"
|
|
10
10
|
],
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"author": "WillBooster Inc.",
|
|
11
13
|
"repository": {
|
|
12
14
|
"type": "git",
|
|
13
15
|
"url": "git+https://github.com/WillBooster/tree-sitter-go.git"
|
|
14
16
|
},
|
|
15
|
-
"license": "MIT",
|
|
16
|
-
"author": "WillBooster Inc.",
|
|
17
17
|
"files": [
|
|
18
18
|
"grammar.js",
|
|
19
19
|
"queries/*.scm",
|
|
@@ -21,6 +21,10 @@
|
|
|
21
21
|
"tree-sitter.json",
|
|
22
22
|
"*.wasm"
|
|
23
23
|
],
|
|
24
|
+
"publishConfig": {
|
|
25
|
+
"access": "public",
|
|
26
|
+
"registry": "https://registry.npmjs.org/"
|
|
27
|
+
},
|
|
24
28
|
"scripts": {
|
|
25
29
|
"build-wasm": "script/generate --build-wasm",
|
|
26
30
|
"build/ci": "bun run build-wasm",
|
|
@@ -43,32 +47,25 @@
|
|
|
43
47
|
"devDependencies": {
|
|
44
48
|
"@tsconfig/bun": "1.0.11",
|
|
45
49
|
"@types/bun": "1.4.3",
|
|
46
|
-
"@vitest/browser-playwright": "5.0.
|
|
47
|
-
"@willbooster/
|
|
48
|
-
"@willbooster/
|
|
49
|
-
"@willbooster/
|
|
50
|
-
"@willbooster/web-tree-sitter": "13.0.0",
|
|
50
|
+
"@vitest/browser-playwright": "5.0.5",
|
|
51
|
+
"@willbooster/oxlint-config": "1.4.9",
|
|
52
|
+
"@willbooster/wb": "22.29.3",
|
|
53
|
+
"@willbooster/web-tree-sitter": "15.0.0",
|
|
51
54
|
"conventional-changelog-conventionalcommits": "10.4.1",
|
|
52
55
|
"lefthook": "2.2.2",
|
|
53
|
-
"oxfmt": "0.73.0",
|
|
54
56
|
"oxlint": "1.88.0",
|
|
55
57
|
"oxlint-tsgolint": "7.0.2004",
|
|
56
|
-
"playwright": "1.64.
|
|
58
|
+
"playwright": "1.64.1",
|
|
57
59
|
"semantic-release": "25.0.9",
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
"wrangler": "4.149.0"
|
|
60
|
+
"vitest": "5.0.5",
|
|
61
|
+
"wrangler": "4.151.1"
|
|
61
62
|
},
|
|
62
63
|
"peerDependencies": {
|
|
63
|
-
"@willbooster/web-tree-sitter": "^
|
|
64
|
+
"@willbooster/web-tree-sitter": "^15.0.0"
|
|
64
65
|
},
|
|
65
66
|
"peerDependenciesMeta": {
|
|
66
67
|
"@willbooster/web-tree-sitter": {
|
|
67
68
|
"optional": true
|
|
68
69
|
}
|
|
69
|
-
},
|
|
70
|
-
"publishConfig": {
|
|
71
|
-
"access": "public",
|
|
72
|
-
"registry": "https://registry.npmjs.org/"
|
|
73
70
|
}
|
|
74
71
|
}
|
package/queries/highlights.scm
CHANGED
|
@@ -93,6 +93,62 @@
|
|
|
93
93
|
(rune_literal)
|
|
94
94
|
] @string
|
|
95
95
|
|
|
96
|
+
((call_expression
|
|
97
|
+
function: (identifier) @function
|
|
98
|
+
arguments: (argument_list
|
|
99
|
+
. (comment)*
|
|
100
|
+
. [
|
|
101
|
+
(interpreted_string_literal
|
|
102
|
+
. [(interpreted_string_literal_content) (escape_sequence) (format_specifier) @string.special]* .)
|
|
103
|
+
(raw_string_literal
|
|
104
|
+
. [(raw_string_literal_content) (format_specifier) @string.special]* .)
|
|
105
|
+
]))
|
|
106
|
+
(#match? @function "^(Printf|Sprintf|Errorf|Scanf|Fatalf|Panicf|Skipf|Logf|Debugf|Infof|Warnf|Warningf|Tracef)$"))
|
|
107
|
+
|
|
108
|
+
((call_expression
|
|
109
|
+
function: (selector_expression field: (field_identifier) @function.method)
|
|
110
|
+
arguments: (argument_list
|
|
111
|
+
. (comment)*
|
|
112
|
+
. [
|
|
113
|
+
(interpreted_string_literal
|
|
114
|
+
. [(interpreted_string_literal_content) (escape_sequence) (format_specifier) @string.special]* .)
|
|
115
|
+
(raw_string_literal
|
|
116
|
+
. [(raw_string_literal_content) (format_specifier) @string.special]* .)
|
|
117
|
+
]))
|
|
118
|
+
(#match? @function.method "^(Printf|Sprintf|Errorf|Scanf|Fatalf|Panicf|Skipf|Logf|Debugf|Infof|Warnf|Warningf|Tracef)$"))
|
|
119
|
+
|
|
120
|
+
((call_expression
|
|
121
|
+
function: (identifier) @function
|
|
122
|
+
arguments: (argument_list
|
|
123
|
+
. (comment)*
|
|
124
|
+
. (_)
|
|
125
|
+
. (comment)*
|
|
126
|
+
. ","
|
|
127
|
+
. (comment)*
|
|
128
|
+
. [
|
|
129
|
+
(interpreted_string_literal
|
|
130
|
+
. [(interpreted_string_literal_content) (escape_sequence) (format_specifier) @string.special]* .)
|
|
131
|
+
(raw_string_literal
|
|
132
|
+
. [(raw_string_literal_content) (format_specifier) @string.special]* .)
|
|
133
|
+
]))
|
|
134
|
+
(#match? @function "^(Fprintf|Appendf|Fscanf|Sscanf)$"))
|
|
135
|
+
|
|
136
|
+
((call_expression
|
|
137
|
+
function: (selector_expression field: (field_identifier) @function.method)
|
|
138
|
+
arguments: (argument_list
|
|
139
|
+
. (comment)*
|
|
140
|
+
. (_)
|
|
141
|
+
. (comment)*
|
|
142
|
+
. ","
|
|
143
|
+
. (comment)*
|
|
144
|
+
. [
|
|
145
|
+
(interpreted_string_literal
|
|
146
|
+
. [(interpreted_string_literal_content) (escape_sequence) (format_specifier) @string.special]* .)
|
|
147
|
+
(raw_string_literal
|
|
148
|
+
. [(raw_string_literal_content) (format_specifier) @string.special]* .)
|
|
149
|
+
]))
|
|
150
|
+
(#match? @function.method "^(Fprintf|Appendf|Fscanf|Sscanf)$"))
|
|
151
|
+
|
|
96
152
|
(escape_sequence) @escape
|
|
97
153
|
|
|
98
154
|
[
|
package/src/node-types.json
CHANGED
|
@@ -1445,6 +1445,10 @@
|
|
|
1445
1445
|
"type": "escape_sequence",
|
|
1446
1446
|
"named": true
|
|
1447
1447
|
},
|
|
1448
|
+
{
|
|
1449
|
+
"type": "format_specifier",
|
|
1450
|
+
"named": true
|
|
1451
|
+
},
|
|
1448
1452
|
{
|
|
1449
1453
|
"type": "interpreted_string_literal_content",
|
|
1450
1454
|
"named": true
|
|
@@ -1879,9 +1883,13 @@
|
|
|
1879
1883
|
"named": true,
|
|
1880
1884
|
"fields": {},
|
|
1881
1885
|
"children": {
|
|
1882
|
-
"multiple":
|
|
1883
|
-
"required":
|
|
1886
|
+
"multiple": true,
|
|
1887
|
+
"required": false,
|
|
1884
1888
|
"types": [
|
|
1889
|
+
{
|
|
1890
|
+
"type": "format_specifier",
|
|
1891
|
+
"named": true
|
|
1892
|
+
},
|
|
1885
1893
|
{
|
|
1886
1894
|
"type": "raw_string_literal_content",
|
|
1887
1895
|
"named": true
|
|
@@ -2940,6 +2948,10 @@
|
|
|
2940
2948
|
"type": "for",
|
|
2941
2949
|
"named": false
|
|
2942
2950
|
},
|
|
2951
|
+
{
|
|
2952
|
+
"type": "format_specifier",
|
|
2953
|
+
"named": true
|
|
2954
|
+
},
|
|
2943
2955
|
{
|
|
2944
2956
|
"type": "func",
|
|
2945
2957
|
"named": false
|
package/tree-sitter-go.wasm
CHANGED
|
Binary file
|