@willbooster/tree-sitter-go 6.1.0 → 6.2.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/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": "6.2.0",
4
4
  "description": "Go grammar for tree-sitter",
5
5
  "keywords": [
6
6
  "go",
@@ -1,5 +1,6 @@
1
1
  (type_identifier) @type
2
2
  (field_identifier) @property
3
+ (tag_name) @attribute
3
4
  (identifier) @variable
4
5
 
5
6
  (call_expression
@@ -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
@@ -14,7 +14,7 @@
14
14
  }
15
15
  ],
16
16
  "metadata": {
17
- "version": "6.1.0",
17
+ "version": "6.2.0",
18
18
  "license": "MIT",
19
19
  "description": "Go grammar for tree-sitter",
20
20
  "authors": [