@willbooster/tree-sitter-go 6.1.0 → 7.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/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  [![Test](https://github.com/WillBooster/tree-sitter-go/actions/workflows/test.yml/badge.svg)](https://github.com/WillBooster/tree-sitter-go/actions/workflows/test.yml)
6
6
  [![Test rust](https://github.com/WillBooster/tree-sitter-go/actions/workflows/test-rust.yml/badge.svg)](https://github.com/WillBooster/tree-sitter-go/actions/workflows/test-rust.yml)
7
7
  [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
8
- [![wbfy](https://img.shields.io/badge/wbfy-20.48.9-1e90ff.svg)](https://github.com/WillBooster/shared/tree/main/packages/wbfy)
8
+ [![wbfy](https://img.shields.io/badge/wbfy-20.51.1-1e90ff.svg)](https://github.com/WillBooster/shared/tree/main/packages/wbfy)
9
9
  [![crates.io](https://img.shields.io/crates/v/willbooster-tree-sitter-go.svg)](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
@@ -17,6 +17,13 @@ This fork extends upstream's version 0.25.0 grammar with method type parameters
17
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
+ ## Support Scope
21
+
22
+ This fork maintains only full parsing: valid input yields a correct tree, and invalid input yields `ERROR` or `MISSING`
23
+ nodes without crashing, hanging, or taking more than linear time. Incremental parsing works as in upstream tree-sitter
24
+ but is not tested here, and no queries (highlights, locals, injections, tags) are shipped. Node types, field names, and
25
+ the trees that error recovery produces may change; such changes are released as new major versions.
26
+
20
27
  ## Usage
21
28
 
22
29
  The npm package ships `tree-sitter-go.wasm` for
@@ -59,7 +66,7 @@ const parser = new Parser();
59
66
  parser.setLanguage(await Language.load(go));
60
67
  ```
61
68
 
62
- The package also ships `grammar.js`, the queries in `queries/`, and the node types in `src/node-types.json`.
69
+ The package also ships `grammar.js` and the node types in `src/node-types.json`.
63
70
 
64
71
  In Rust, depend on the [crate](https://crates.io/crates/willbooster-tree-sitter-go) and on
65
72
  [willbooster-tree-sitter](https://crates.io/crates/willbooster-tree-sitter), the runtime this package is tested and
@@ -68,7 +75,7 @@ fuzzed with:
68
75
  ```toml
69
76
  [dependencies]
70
77
  tree-sitter = { package = "willbooster-tree-sitter", version = "15.0.0" }
71
- tree-sitter-go = { package = "willbooster-tree-sitter-go", version = "6" }
78
+ tree-sitter-go = { package = "willbooster-tree-sitter-go", version = "7" }
72
79
  ```
73
80
 
74
81
  ```rust
@@ -104,9 +111,6 @@ and the release build regenerate the parsers before compiling them.
104
111
  `bun run test` runs:
105
112
 
106
113
  - the corpus in `test/corpus`, with the native build and with the Wasm build (the first run downloads the WASI SDK);
107
- - an incremental-parsing check (`test/unit/incremental.test.ts`): `script/fuzz-corpus` runs `tree-sitter fuzz`, which
108
- edits each corpus case at random, reparses it, undoes the edits, and reparses again. `TREE_SITTER_SEED`,
109
- `TREE_SITTER_ITERATIONS`, and `TREE_SITTER_EDITS` run other or more edits;
110
114
  - a check that the real-world Go files in `examples/`, the checked-in ones and those of the cloned repositories, fail to
111
115
  parse exactly as listed in `script/known-failures.txt`. Many of the listed files are test data that is invalid Go on
112
116
  purpose. The first run clones the repositories. The example repositories are pinned to commits in
@@ -122,8 +126,7 @@ and the release build regenerate the parsers before compiling them.
122
126
  Cloudflare Workers with and without Node.js compatibility (`test/e2e/workers.test.ts`).
123
127
 
124
128
  The tests and `script/parse-examples` compile the parser into `.tmp/tree-sitter-lib` rather than the CLI's cache shared
125
- by every checkout; `script/fuzz-corpus` builds a parser of its own in `.tmp/fuzz` for each run and deletes it
126
- afterwards.
129
+ by every checkout.
127
130
 
128
131
  CI also runs these tests on Linux arm64 and macOS, where the CLI compiles the parser natively, and fuzzes the parser
129
132
  with libFuzzer and sanitizers (`.github/workflows/robustness.yml`).
package/grammar.js CHANGED
@@ -86,6 +86,7 @@ module.exports = grammar({
86
86
  word: $ => $.identifier,
87
87
 
88
88
  conflicts: $ => [
89
+ [$._raw_struct_tag, $.struct_tag_pair],
89
90
  [$._generic_function, $._expression],
90
91
  [$._generic_function, $._simple_type, $._expression],
91
92
  [$._generic_function, $._simple_type, $.generic_type, $._expression],
@@ -393,9 +394,58 @@ module.exports = grammar({
393
394
  )),
394
395
  ),
395
396
  ),
396
- field('tag', optional($._string_literal)),
397
+ field('tag', optional(choice(
398
+ $.interpreted_string_literal,
399
+ alias($._raw_struct_tag, $.raw_string_literal),
400
+ ))),
401
+ ),
402
+
403
+ _raw_struct_tag: $ => seq(
404
+ '`',
405
+ repeat(choice(
406
+ $.struct_tag_pair,
407
+ alias($._struct_tag_key_content, $.raw_string_literal_content),
408
+ alias($._struct_tag_percent, $.raw_string_literal_content),
409
+ alias($._struct_tag_key_format_specifier, $.format_specifier),
410
+ $.format_specifier,
411
+ alias($._struct_tag_colon, $.raw_string_literal_content),
412
+ alias($._struct_tag_quote, $.raw_string_literal_content),
413
+ alias(token.immediate(/[\x00-\x20\x7f]/), $.raw_string_literal_content),
414
+ )),
415
+ token.immediate('`'),
416
+ ),
417
+
418
+ struct_tag_pair: $ => prec.dynamic(1, seq(
419
+ field('key', alias($._struct_tag_key, $.tag_name)),
420
+ alias($._struct_tag_colon, ':'),
421
+ field('value', alias($._struct_tag_value, $.interpreted_string_literal)),
422
+ )),
423
+
424
+ _struct_tag_key: $ => repeat1(choice(
425
+ $._struct_tag_key_content,
426
+ alias($._struct_tag_percent, $.raw_string_literal_content),
427
+ alias($._struct_tag_key_format_specifier, $.format_specifier),
428
+ )),
429
+
430
+ _struct_tag_key_content: _ => token.immediate(/[^\x00-\x20\x7f:"`%]+/),
431
+
432
+ _struct_tag_percent: _ => token.immediate(/%/),
433
+
434
+ _struct_tag_key_format_specifier: _ => formatSpecifier(/[+#0-]*/, 3),
435
+
436
+ _struct_tag_value: $ => interpretedStringLiteral(
437
+ $,
438
+ alias($._struct_tag_quote, '"'),
439
+ alias($._struct_tag_quote, '"'),
440
+ true,
397
441
  ),
398
442
 
443
+ _struct_tag_escape_sequence: _ => escapeSequence(/[^xuU`\n]/),
444
+
445
+ _struct_tag_colon: _ => token.immediate(':'),
446
+
447
+ _struct_tag_quote: _ => token.immediate('"'),
448
+
399
449
  interface_type: $ => seq(
400
450
  'interface',
401
451
  '{',
@@ -895,36 +945,11 @@ module.exports = grammar({
895
945
  token.immediate('`'),
896
946
  ),
897
947
 
898
- interpreted_string_literal: $ => seq(
899
- '"',
900
- repeat(choice(
901
- alias(token.immediate(prec(1, /[^"\n\\%]+/)), $.interpreted_string_literal_content),
902
- alias(token.immediate('%'), $.interpreted_string_literal_content),
903
- $.format_specifier,
904
- $.escape_sequence,
905
- )),
906
- token.immediate('"'),
907
- ),
948
+ interpreted_string_literal: $ => interpretedStringLiteral($, '"'),
908
949
 
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
- ))),
950
+ format_specifier: _ => formatSpecifier(/[+#0 -]*/),
917
951
 
918
- escape_sequence: _ => token.immediate(seq(
919
- '\\',
920
- choice(
921
- /[^xuU]/,
922
- /\d{2,3}/,
923
- /x[0-9a-fA-F]{2,}/,
924
- /u[0-9a-fA-F]{4}/,
925
- /U[0-9a-fA-F]{8}/,
926
- ),
927
- )),
952
+ escape_sequence: _ => escapeSequence(/[^xuU]/),
928
953
 
929
954
  int_literal: _ => token(intLiteral),
930
955
 
@@ -1013,3 +1038,40 @@ function commaSep1(rule) {
1013
1038
  function commaSep(rule) {
1014
1039
  return optional(commaSep1(rule));
1015
1040
  }
1041
+
1042
+ function interpretedStringLiteral($, openingQuote, closingQuote = token.immediate('"'), insideRawTag = false) {
1043
+ return seq(
1044
+ openingQuote,
1045
+ repeat(choice(
1046
+ alias(token.immediate(prec(1, insideRawTag ? /[^"`\n\\%]+/ : /[^"\n\\%]+/)), $.interpreted_string_literal_content),
1047
+ alias(token.immediate('%'), $.interpreted_string_literal_content),
1048
+ $.format_specifier,
1049
+ insideRawTag ? alias($._struct_tag_escape_sequence, $.escape_sequence) : $.escape_sequence,
1050
+ )),
1051
+ closingQuote,
1052
+ );
1053
+ }
1054
+
1055
+ function escapeSequence(simpleEscape) {
1056
+ return token.immediate(seq(
1057
+ '\\',
1058
+ choice(
1059
+ simpleEscape,
1060
+ /\d{2,3}/,
1061
+ /x[0-9a-fA-F]{2,}/,
1062
+ /u[0-9a-fA-F]{4}/,
1063
+ /U[0-9a-fA-F]{8}/,
1064
+ ),
1065
+ ));
1066
+ }
1067
+
1068
+ function formatSpecifier(flags, precedence = 2) {
1069
+ return token.immediate(prec(precedence, seq(
1070
+ '%',
1071
+ flags,
1072
+ optional(choice(/[0-9]+/, seq(optional(formatArgumentIndex), '*'))),
1073
+ optional(seq('.', choice(/[0-9]*/, seq(optional(formatArgumentIndex), '*')))),
1074
+ optional(formatArgumentIndex),
1075
+ /[vTtbcdoOqxXUeEfFgGspw%]/,
1076
+ )));
1077
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/tree-sitter-go",
3
- "version": "6.1.0",
3
+ "version": "7.0.0",
4
4
  "description": "Go grammar for tree-sitter",
5
5
  "keywords": [
6
6
  "go",
@@ -16,7 +16,6 @@
16
16
  },
17
17
  "files": [
18
18
  "grammar.js",
19
- "queries/*.scm",
20
19
  "src/node-types.json",
21
20
  "tree-sitter.json",
22
21
  "*.wasm"
@@ -46,15 +45,15 @@
46
45
  },
47
46
  "devDependencies": {
48
47
  "@tsconfig/bun": "1.0.11",
49
- "@types/bun": "1.4.3",
48
+ "@types/bun": "1.4.4",
50
49
  "@vitest/browser-playwright": "5.0.5",
51
50
  "@willbooster/oxlint-config": "1.4.9",
52
- "@willbooster/wb": "22.29.3",
53
- "@willbooster/web-tree-sitter": "15.0.0",
51
+ "@willbooster/wb": "22.32.3",
52
+ "@willbooster/web-tree-sitter": "15.5.4",
54
53
  "conventional-changelog-conventionalcommits": "10.4.1",
55
54
  "lefthook": "2.2.2",
56
- "oxlint": "1.88.0",
57
- "oxlint-tsgolint": "7.0.2004",
55
+ "oxlint": "1.89.0",
56
+ "oxlint-tsgolint": "7.0.2005",
58
57
  "playwright": "1.64.1",
59
58
  "semantic-release": "25.0.9",
60
59
  "vitest": "5.0.5",
@@ -263,6 +263,16 @@
263
263
  }
264
264
  ]
265
265
  },
266
+ {
267
+ "type": "\"",
268
+ "named": false,
269
+ "fields": {}
270
+ },
271
+ {
272
+ "type": ":",
273
+ "named": false,
274
+ "fields": {}
275
+ },
266
276
  {
267
277
  "type": "argument_list",
268
278
  "named": true,
@@ -1893,10 +1903,19 @@
1893
1903
  {
1894
1904
  "type": "raw_string_literal_content",
1895
1905
  "named": true
1906
+ },
1907
+ {
1908
+ "type": "struct_tag_pair",
1909
+ "named": true
1896
1910
  }
1897
1911
  ]
1898
1912
  }
1899
1913
  },
1914
+ {
1915
+ "type": "raw_string_literal_content",
1916
+ "named": true,
1917
+ "fields": {}
1918
+ },
1900
1919
  {
1901
1920
  "type": "receive_statement",
1902
1921
  "named": true,
@@ -2148,6 +2167,32 @@
2148
2167
  ]
2149
2168
  }
2150
2169
  },
2170
+ {
2171
+ "type": "struct_tag_pair",
2172
+ "named": true,
2173
+ "fields": {
2174
+ "key": {
2175
+ "multiple": false,
2176
+ "required": true,
2177
+ "types": [
2178
+ {
2179
+ "type": "tag_name",
2180
+ "named": true
2181
+ }
2182
+ ]
2183
+ },
2184
+ "value": {
2185
+ "multiple": false,
2186
+ "required": true,
2187
+ "types": [
2188
+ {
2189
+ "type": "interpreted_string_literal",
2190
+ "named": true
2191
+ }
2192
+ ]
2193
+ }
2194
+ }
2195
+ },
2151
2196
  {
2152
2197
  "type": "struct_type",
2153
2198
  "named": true,
@@ -2163,6 +2208,25 @@
2163
2208
  ]
2164
2209
  }
2165
2210
  },
2211
+ {
2212
+ "type": "tag_name",
2213
+ "named": true,
2214
+ "fields": {},
2215
+ "children": {
2216
+ "multiple": true,
2217
+ "required": false,
2218
+ "types": [
2219
+ {
2220
+ "type": "format_specifier",
2221
+ "named": true
2222
+ },
2223
+ {
2224
+ "type": "raw_string_literal_content",
2225
+ "named": true
2226
+ }
2227
+ ]
2228
+ }
2229
+ },
2166
2230
  {
2167
2231
  "type": "type_alias",
2168
2232
  "named": true,
@@ -2715,10 +2779,6 @@
2715
2779
  "type": "!=",
2716
2780
  "named": false
2717
2781
  },
2718
- {
2719
- "type": "\"",
2720
- "named": false
2721
- },
2722
2782
  {
2723
2783
  "type": "%",
2724
2784
  "named": false
@@ -2807,10 +2867,6 @@
2807
2867
  "type": "/=",
2808
2868
  "named": false
2809
2869
  },
2810
- {
2811
- "type": ":",
2812
- "named": false
2813
- },
2814
2870
  {
2815
2871
  "type": ":=",
2816
2872
  "named": false
@@ -3020,10 +3076,6 @@
3020
3076
  "type": "range",
3021
3077
  "named": false
3022
3078
  },
3023
- {
3024
- "type": "raw_string_literal_content",
3025
- "named": true
3026
- },
3027
3079
  {
3028
3080
  "type": "return",
3029
3081
  "named": false
Binary file
package/tree-sitter.json CHANGED
@@ -8,13 +8,11 @@
8
8
  "path": ".",
9
9
  "file-types": [
10
10
  "go"
11
- ],
12
- "highlights": "queries/highlights.scm",
13
- "tags": "queries/tags.scm"
11
+ ]
14
12
  }
15
13
  ],
16
14
  "metadata": {
17
- "version": "6.1.0",
15
+ "version": "7.0.0",
18
16
  "license": "MIT",
19
17
  "description": "Go grammar for tree-sitter",
20
18
  "authors": [
@@ -1,167 +0,0 @@
1
- (type_identifier) @type
2
- (field_identifier) @property
3
- (identifier) @variable
4
-
5
- (call_expression
6
- function: (identifier) @function)
7
-
8
- (call_expression
9
- function: (identifier) @function.builtin
10
- (#match? @function.builtin "^(append|cap|clear|close|complex|copy|delete|imag|len|make|max|min|new|panic|print|println|real|recover)$"))
11
-
12
- (call_expression
13
- function: (selector_expression
14
- field: (field_identifier) @function.method))
15
-
16
- (function_declaration
17
- name: (identifier) @function)
18
-
19
- (method_declaration
20
- name: (field_identifier) @function.method)
21
-
22
- [
23
- "--"
24
- "-"
25
- "-="
26
- ":="
27
- "!"
28
- "!="
29
- "..."
30
- "*"
31
- "*"
32
- "*="
33
- "/"
34
- "/="
35
- "&"
36
- "&&"
37
- "&="
38
- "%"
39
- "%="
40
- "^"
41
- "^="
42
- "+"
43
- "++"
44
- "+="
45
- "<-"
46
- "<"
47
- "<<"
48
- "<<="
49
- "<="
50
- "="
51
- "=="
52
- ">"
53
- ">="
54
- ">>"
55
- ">>="
56
- "|"
57
- "|="
58
- "||"
59
- "~"
60
- ] @operator
61
-
62
- [
63
- "break"
64
- "case"
65
- "chan"
66
- "const"
67
- "continue"
68
- "default"
69
- "defer"
70
- "else"
71
- "fallthrough"
72
- "for"
73
- "func"
74
- "go"
75
- "goto"
76
- "if"
77
- "import"
78
- "interface"
79
- "map"
80
- "package"
81
- "range"
82
- "return"
83
- "select"
84
- "struct"
85
- "switch"
86
- "type"
87
- "var"
88
- ] @keyword
89
-
90
- [
91
- (interpreted_string_literal)
92
- (raw_string_literal)
93
- (rune_literal)
94
- ] @string
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
-
152
- (escape_sequence) @escape
153
-
154
- [
155
- (int_literal)
156
- (float_literal)
157
- (imaginary_literal)
158
- ] @number
159
-
160
- [
161
- (true)
162
- (false)
163
- (nil)
164
- (iota)
165
- ] @constant.builtin
166
-
167
- (comment) @comment
package/queries/tags.scm DELETED
@@ -1,70 +0,0 @@
1
- (
2
- (comment)* @doc
3
- .
4
- (function_declaration
5
- name: (identifier) @name) @definition.function
6
- (#strip! @doc "^//\\s*")
7
- (#select-adjacent! @doc @definition.function)
8
- )
9
-
10
- (
11
- (comment)* @doc
12
- .
13
- (method_declaration
14
- name: (field_identifier) @name) @definition.method
15
- (#strip! @doc "^//\\s*")
16
- (#select-adjacent! @doc @definition.method)
17
- )
18
-
19
- (call_expression
20
- function: [
21
- (identifier) @name
22
- (parenthesized_expression (identifier) @name)
23
- (selector_expression field: (field_identifier) @name)
24
- (parenthesized_expression (selector_expression field: (field_identifier) @name))
25
- ]) @reference.call
26
-
27
- (
28
- (type_spec
29
- name: (type_identifier) @name) @definition.type
30
- (#not-eq? @name "_")
31
- )
32
-
33
- (
34
- (type_alias
35
- name: (type_identifier) @name) @definition.type
36
- (#not-eq? @name "_")
37
- )
38
-
39
- (type_identifier) @name @reference.type
40
-
41
- (package_clause "package" (package_identifier) @name)
42
-
43
- (method_elem
44
- name: (field_identifier) @name) @definition.method
45
-
46
- (
47
- (field_declaration
48
- name: (field_identifier) @name) @definition.field
49
- (#not-eq? @name "_")
50
- )
51
-
52
- (import_declaration (import_spec) @name)
53
-
54
- (
55
- (source_file
56
- (var_declaration
57
- [
58
- (var_spec name: (identifier) @name) @definition.variable
59
- (var_spec_list
60
- (var_spec name: (identifier) @name) @definition.variable)
61
- ]))
62
- (#not-eq? @name "_")
63
- )
64
-
65
- (
66
- (source_file
67
- (const_declaration
68
- (const_spec name: (identifier) @name) @definition.constant))
69
- (#not-eq? @name "_")
70
- )