@willbooster/tree-sitter-go 6.0.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
@@ -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',
@@ -85,6 +86,7 @@ module.exports = grammar({
85
86
  word: $ => $.identifier,
86
87
 
87
88
  conflicts: $ => [
89
+ [$._raw_struct_tag, $.struct_tag_pair],
88
90
  [$._generic_function, $._expression],
89
91
  [$._generic_function, $._simple_type, $._expression],
90
92
  [$._generic_function, $._simple_type, $.generic_type, $._expression],
@@ -392,9 +394,58 @@ module.exports = grammar({
392
394
  )),
393
395
  ),
394
396
  ),
395
- field('tag', optional($._string_literal)),
397
+ field('tag', optional(choice(
398
+ $.interpreted_string_literal,
399
+ alias($._raw_struct_tag, $.raw_string_literal),
400
+ ))),
396
401
  ),
397
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,
441
+ ),
442
+
443
+ _struct_tag_escape_sequence: _ => escapeSequence(/[^xuU`\n]/),
444
+
445
+ _struct_tag_colon: _ => token.immediate(':'),
446
+
447
+ _struct_tag_quote: _ => token.immediate('"'),
448
+
398
449
  interface_type: $ => seq(
399
450
  'interface',
400
451
  '{',
@@ -886,29 +937,19 @@ module.exports = grammar({
886
937
 
887
938
  raw_string_literal: $ => seq(
888
939
  '`',
889
- alias(token(prec(1, /[^`]*/)), $.raw_string_literal_content),
890
- '`',
891
- ),
892
-
893
- interpreted_string_literal: $ => seq(
894
- '"',
895
940
  repeat(choice(
896
- alias(token.immediate(prec(1, /[^"\n\\]+/)), $.interpreted_string_literal_content),
897
- $.escape_sequence,
941
+ alias(token.immediate(prec(1, /[^`%]+/)), $.raw_string_literal_content),
942
+ alias(token.immediate('%'), $.raw_string_literal_content),
943
+ $.format_specifier,
898
944
  )),
899
- token.immediate('"'),
945
+ token.immediate('`'),
900
946
  ),
901
947
 
902
- escape_sequence: _ => token.immediate(seq(
903
- '\\',
904
- choice(
905
- /[^xuU]/,
906
- /\d{2,3}/,
907
- /x[0-9a-fA-F]{2,}/,
908
- /u[0-9a-fA-F]{4}/,
909
- /U[0-9a-fA-F]{8}/,
910
- ),
911
- )),
948
+ interpreted_string_literal: $ => interpretedStringLiteral($, '"'),
949
+
950
+ format_specifier: _ => formatSpecifier(/[+#0 -]*/),
951
+
952
+ escape_sequence: _ => escapeSequence(/[^xuU]/),
912
953
 
913
954
  int_literal: _ => token(intLiteral),
914
955
 
@@ -997,3 +1038,40 @@ function commaSep1(rule) {
997
1038
  function commaSep(rule) {
998
1039
  return optional(commaSep1(rule));
999
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.0.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
@@ -93,6 +94,62 @@
93
94
  (rune_literal)
94
95
  ] @string
95
96
 
97
+ ((call_expression
98
+ function: (identifier) @function
99
+ arguments: (argument_list
100
+ . (comment)*
101
+ . [
102
+ (interpreted_string_literal
103
+ . [(interpreted_string_literal_content) (escape_sequence) (format_specifier) @string.special]* .)
104
+ (raw_string_literal
105
+ . [(raw_string_literal_content) (format_specifier) @string.special]* .)
106
+ ]))
107
+ (#match? @function "^(Printf|Sprintf|Errorf|Scanf|Fatalf|Panicf|Skipf|Logf|Debugf|Infof|Warnf|Warningf|Tracef)$"))
108
+
109
+ ((call_expression
110
+ function: (selector_expression field: (field_identifier) @function.method)
111
+ arguments: (argument_list
112
+ . (comment)*
113
+ . [
114
+ (interpreted_string_literal
115
+ . [(interpreted_string_literal_content) (escape_sequence) (format_specifier) @string.special]* .)
116
+ (raw_string_literal
117
+ . [(raw_string_literal_content) (format_specifier) @string.special]* .)
118
+ ]))
119
+ (#match? @function.method "^(Printf|Sprintf|Errorf|Scanf|Fatalf|Panicf|Skipf|Logf|Debugf|Infof|Warnf|Warningf|Tracef)$"))
120
+
121
+ ((call_expression
122
+ function: (identifier) @function
123
+ arguments: (argument_list
124
+ . (comment)*
125
+ . (_)
126
+ . (comment)*
127
+ . ","
128
+ . (comment)*
129
+ . [
130
+ (interpreted_string_literal
131
+ . [(interpreted_string_literal_content) (escape_sequence) (format_specifier) @string.special]* .)
132
+ (raw_string_literal
133
+ . [(raw_string_literal_content) (format_specifier) @string.special]* .)
134
+ ]))
135
+ (#match? @function "^(Fprintf|Appendf|Fscanf|Sscanf)$"))
136
+
137
+ ((call_expression
138
+ function: (selector_expression field: (field_identifier) @function.method)
139
+ arguments: (argument_list
140
+ . (comment)*
141
+ . (_)
142
+ . (comment)*
143
+ . ","
144
+ . (comment)*
145
+ . [
146
+ (interpreted_string_literal
147
+ . [(interpreted_string_literal_content) (escape_sequence) (format_specifier) @string.special]* .)
148
+ (raw_string_literal
149
+ . [(raw_string_literal_content) (format_specifier) @string.special]* .)
150
+ ]))
151
+ (#match? @function.method "^(Fprintf|Appendf|Fscanf|Sscanf)$"))
152
+
96
153
  (escape_sequence) @escape
97
154
 
98
155
  [
@@ -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,
@@ -1445,6 +1455,10 @@
1445
1455
  "type": "escape_sequence",
1446
1456
  "named": true
1447
1457
  },
1458
+ {
1459
+ "type": "format_specifier",
1460
+ "named": true
1461
+ },
1448
1462
  {
1449
1463
  "type": "interpreted_string_literal_content",
1450
1464
  "named": true
@@ -1879,16 +1893,29 @@
1879
1893
  "named": true,
1880
1894
  "fields": {},
1881
1895
  "children": {
1882
- "multiple": false,
1883
- "required": true,
1896
+ "multiple": true,
1897
+ "required": false,
1884
1898
  "types": [
1899
+ {
1900
+ "type": "format_specifier",
1901
+ "named": true
1902
+ },
1885
1903
  {
1886
1904
  "type": "raw_string_literal_content",
1887
1905
  "named": true
1906
+ },
1907
+ {
1908
+ "type": "struct_tag_pair",
1909
+ "named": true
1888
1910
  }
1889
1911
  ]
1890
1912
  }
1891
1913
  },
1914
+ {
1915
+ "type": "raw_string_literal_content",
1916
+ "named": true,
1917
+ "fields": {}
1918
+ },
1892
1919
  {
1893
1920
  "type": "receive_statement",
1894
1921
  "named": true,
@@ -2140,6 +2167,32 @@
2140
2167
  ]
2141
2168
  }
2142
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
+ },
2143
2196
  {
2144
2197
  "type": "struct_type",
2145
2198
  "named": true,
@@ -2155,6 +2208,25 @@
2155
2208
  ]
2156
2209
  }
2157
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
+ },
2158
2230
  {
2159
2231
  "type": "type_alias",
2160
2232
  "named": true,
@@ -2707,10 +2779,6 @@
2707
2779
  "type": "!=",
2708
2780
  "named": false
2709
2781
  },
2710
- {
2711
- "type": "\"",
2712
- "named": false
2713
- },
2714
2782
  {
2715
2783
  "type": "%",
2716
2784
  "named": false
@@ -2799,10 +2867,6 @@
2799
2867
  "type": "/=",
2800
2868
  "named": false
2801
2869
  },
2802
- {
2803
- "type": ":",
2804
- "named": false
2805
- },
2806
2870
  {
2807
2871
  "type": ":=",
2808
2872
  "named": false
@@ -2940,6 +3004,10 @@
2940
3004
  "type": "for",
2941
3005
  "named": false
2942
3006
  },
3007
+ {
3008
+ "type": "format_specifier",
3009
+ "named": true
3010
+ },
2943
3011
  {
2944
3012
  "type": "func",
2945
3013
  "named": false
@@ -3008,10 +3076,6 @@
3008
3076
  "type": "range",
3009
3077
  "named": false
3010
3078
  },
3011
- {
3012
- "type": "raw_string_literal_content",
3013
- "named": true
3014
- },
3015
3079
  {
3016
3080
  "type": "return",
3017
3081
  "named": false
Binary file
package/tree-sitter.json CHANGED
@@ -14,7 +14,7 @@
14
14
  }
15
15
  ],
16
16
  "metadata": {
17
- "version": "6.0.0",
17
+ "version": "6.2.0",
18
18
  "license": "MIT",
19
19
  "description": "Go grammar for tree-sitter",
20
20
  "authors": [