tree-sitter-ucode 0.4.0 → 0.5.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.
Binary file
Binary file
package/tree-sitter.json CHANGED
@@ -50,10 +50,23 @@
50
50
  "markup/queries/textobjects.scm"
51
51
  ],
52
52
  "injection-regex": "^ucode_markup$"
53
+ },
54
+ {
55
+ "name": "ucdocs",
56
+ "camelcase": "Ucdocs",
57
+ "path": "./ucdocs",
58
+ "file-types": null,
59
+ "highlights": [
60
+ "ucdocs/queries/highlights.scm"
61
+ ],
62
+ "tags": [
63
+ "ucdocs/queries/tags.scm"
64
+ ],
65
+ "injection-regex": "^ucdocs$"
53
66
  }
54
67
  ],
55
68
  "metadata": {
56
- "version": "0.4.0",
69
+ "version": "0.5.0",
57
70
  "license": "MIT",
58
71
  "description": "Ucode grammar for tree-sitter",
59
72
  "links": {
@@ -0,0 +1,284 @@
1
+ /**
2
+ * @file Ucdocs grammar for tree-sitter
3
+ * @license MIT
4
+ */
5
+
6
+ /// <reference types="tree-sitter-cli/dsl" />
7
+ // @ts-check
8
+
9
+ module.exports = grammar({
10
+ name: 'ucdocs',
11
+
12
+ extras: _ => [
13
+ token(choice(
14
+ // Skip leading stars at the start of each line (e.g. " * " in block comments)
15
+ seq(/\n/, /[ \t]*/, repeat(seq('*', /[ \t]*/))),
16
+ /\s/,
17
+ )),
18
+ ],
19
+
20
+ rules: {
21
+ document: $ => seq(
22
+ $._begin,
23
+ optional(alias($._free_description, $.description)),
24
+ repeat(choice(
25
+ $.param_tag,
26
+ $.returns_tag,
27
+ $.template_tag,
28
+ $.typedef_tag,
29
+ $.type_tag,
30
+ $.throws_tag,
31
+ $.deprecated_tag,
32
+ $.since_tag,
33
+ $.see_tag,
34
+ $.example_tag,
35
+ $.default_tag,
36
+ $.unknown_tag,
37
+ )),
38
+ $._end,
39
+ ),
40
+
41
+ _begin: _ => seq('/', repeat('*')),
42
+ _end: _ => '/',
43
+
44
+ // Used after a type_expression/rest_type_expression has already claimed `{` at
45
+ // this position (param_tag, returns_tag, throws_tag) — excludes _brace_text so
46
+ // it never competes with a legitimate {type} for the leading `{`.
47
+ _typed_description: $ => prec.right(seq(
48
+ choice($._text, $.inline_tag),
49
+ repeat(choice($._text, $.inline_tag)),
50
+ )),
51
+
52
+ // Used wherever no type_expression can appear at the same position, so a bare
53
+ // `{` can only be an inline tag or arbitrary brace-text (e.g. @example code).
54
+ _free_description: $ => prec.right(seq(
55
+ choice($._text, $.inline_tag, $._brace_text),
56
+ repeat(choice($._text, $.inline_tag, $._brace_text)),
57
+ )),
58
+
59
+ // {@link target text} and similar inline JSDoc tags embedded in description text.
60
+ inline_tag: $ => seq(
61
+ '{',
62
+ $.tag_name,
63
+ optional(alias($._free_description, $.description)),
64
+ '}',
65
+ ),
66
+
67
+ // A `{` not immediately followed by `@tagname` is not an inline tag — e.g. an
68
+ // object literal or arrow-function block in an @example code block. Recursive
69
+ // so nested braces (object literals inside arrow functions, etc.) stay balanced
70
+ // instead of erroring out on the first inner `}`.
71
+ _brace_text: $ => seq(
72
+ '{',
73
+ optional(seq(
74
+ /[^{}@]/,
75
+ repeat(choice(
76
+ /[^{}]+/,
77
+ $._brace_text,
78
+ )),
79
+ )),
80
+ '}',
81
+ ),
82
+
83
+ param_tag: $ => seq(
84
+ '@param',
85
+ optional(field('type', choice($.type_expression, $.rest_type_expression))),
86
+ optional(field('name', choice($.identifier, $.optional_param))),
87
+ optional(field('description', alias($._typed_description, $.description))),
88
+ ),
89
+
90
+ // [name] or [name=default] — marks the parameter as optional, JSDoc-style.
91
+ optional_param: $ => seq(
92
+ '[',
93
+ field('name', $.param_path),
94
+ optional(seq('=', field('default', $.default_value))),
95
+ ']',
96
+ ),
97
+
98
+ // Dotted parameter paths, e.g. opts.precision for nested option fields.
99
+ param_path: $ => seq(
100
+ $.identifier,
101
+ repeat(seq('.', $.identifier)),
102
+ ),
103
+
104
+ default_value: _ => token(choice(
105
+ /-?\d+(\.\d+)?/,
106
+ /[a-zA-Z_$][a-zA-Z0-9_$]*/,
107
+ )),
108
+
109
+ returns_tag: $ => seq(
110
+ choice('@returns', '@return'),
111
+ optional(field('type', $.type_expression)),
112
+ optional(field('description', alias($._typed_description, $.description))),
113
+ ),
114
+
115
+ template_tag: $ => seq(
116
+ '@template',
117
+ commaSep1(alias($.type_identifier, $.type_param)),
118
+ ),
119
+
120
+ typedef_tag: $ => seq(
121
+ '@typedef',
122
+ optional(field('type', $.type_expression)),
123
+ field('name', $.type_identifier),
124
+ ),
125
+
126
+ type_tag: $ => seq(
127
+ '@type',
128
+ field('type', $.type_expression),
129
+ ),
130
+
131
+ throws_tag: $ => seq(
132
+ choice('@throws', '@throw'),
133
+ optional(field('type', $.type_expression)),
134
+ optional(field('description', alias($._typed_description, $.description))),
135
+ ),
136
+
137
+ deprecated_tag: $ => seq(
138
+ '@deprecated',
139
+ optional(field('description', alias($._free_description, $.description))),
140
+ ),
141
+
142
+ since_tag: $ => seq(
143
+ '@since',
144
+ optional(field('description', alias($._free_description, $.description))),
145
+ ),
146
+
147
+ see_tag: $ => seq(
148
+ '@see',
149
+ optional(field('description', alias($._free_description, $.description))),
150
+ ),
151
+
152
+ example_tag: $ => seq(
153
+ '@example',
154
+ optional(field('description', alias($._free_description, $.description))),
155
+ ),
156
+
157
+ default_tag: $ => seq(
158
+ '@default',
159
+ optional(field('description', alias($._free_description, $.description))),
160
+ ),
161
+
162
+ unknown_tag: $ => seq(
163
+ $.tag_name,
164
+ optional(field('description', alias($._free_description, $.description))),
165
+ ),
166
+
167
+ tag_name: _ => /@[a-zA-Z_]+/,
168
+
169
+ // ── Type expressions ────────────────────────────────────────────────────
170
+
171
+ type_expression: $ => seq('{', $._type, '}'),
172
+
173
+ // {..Type} — only valid on @param, signals a rest/variadic parameter.
174
+ rest_type_expression: $ => seq('{', '...', $._type, '}'),
175
+
176
+ _type: $ => choice(
177
+ $.primitive_type,
178
+ $.list_type,
179
+ $.dict_type,
180
+ $.record_type,
181
+ $.named_type,
182
+ $.module_type,
183
+ $.function_type,
184
+ $.anon_function_type,
185
+ $.union_type,
186
+ $.nullable_type,
187
+ $.any_type,
188
+ ),
189
+
190
+ primitive_type: _ => choice('int', 'float', 'string', 'boolean', 'null', 'void'),
191
+
192
+ any_type: _ => choice('*', 'any'),
193
+
194
+ list_type: $ => seq(
195
+ 'list',
196
+ '<',
197
+ field('element', $._type),
198
+ '>',
199
+ ),
200
+
201
+ dict_type: $ => seq(
202
+ 'dict',
203
+ '<',
204
+ field('value', $._type),
205
+ '>',
206
+ ),
207
+
208
+ record_type: $ => seq(
209
+ '{',
210
+ commaSep($.record_field),
211
+ '}',
212
+ ),
213
+
214
+ record_field: $ => seq(
215
+ field('name', $.identifier),
216
+ ':',
217
+ field('type', $._type),
218
+ ),
219
+
220
+ // module:core.ParseConfig — cross-module type reference used by stdlib docs.
221
+ module_type: $ => seq(
222
+ 'module:',
223
+ field('path', $.module_path),
224
+ ),
225
+
226
+ module_path: _ => /[a-zA-Z_$][a-zA-Z0-9_$]*(\.[a-zA-Z_$][a-zA-Z0-9_$]*)*/,
227
+
228
+ // Covers bare TypeName and generic TypeName<T>, TypeName<T, U>, etc.
229
+ named_type: $ => seq(
230
+ field('name', $.type_identifier),
231
+ optional(seq(
232
+ '<',
233
+ field('params', commaSep1($._type)),
234
+ '>',
235
+ )),
236
+ ),
237
+
238
+ function_type: $ => seq(
239
+ '(',
240
+ field('params', commaSep($.function_param)),
241
+ ')',
242
+ '=>',
243
+ field('return', $._type),
244
+ ),
245
+
246
+ function_param: $ => seq(
247
+ field('name', $.identifier),
248
+ ':',
249
+ field('type', $._type),
250
+ ),
251
+
252
+ // JSDoc anonymous function syntax: function(T, U): V (no parameter names).
253
+ // Return type is optional to allow bare function(T) declarations.
254
+ anon_function_type: $ => seq(
255
+ 'function',
256
+ '(',
257
+ field('params', commaSep($._type)),
258
+ ')',
259
+ optional(seq(':', field('return', $._type))),
260
+ ),
261
+
262
+ // Left-associative so T | U | V parses as (T | U) | V.
263
+ union_type: $ => prec.left(1, seq($._type, '|', $._type)),
264
+
265
+ // ?T is sugar for T | null; higher precedence than union so ?T | U == (?T) | U.
266
+ nullable_type: $ => prec(2, seq('?', $._type)),
267
+
268
+ // PascalCase names: typedef references and type parameters.
269
+ type_identifier: _ => /[A-Z][a-zA-Z0-9]*/,
270
+
271
+ // Lowercase-starting names: parameter names and function param names.
272
+ identifier: _ => /[a-z_$][a-zA-Z_$0-9]*/,
273
+
274
+ _text: _ => token(prec(-1, /[^*{}@\s][^*{}@\n]*/)),
275
+ },
276
+ });
277
+
278
+ function commaSep(rule) {
279
+ return optional(commaSep1(rule));
280
+ }
281
+
282
+ function commaSep1(rule) {
283
+ return seq(rule, repeat(seq(',', rule)));
284
+ }
@@ -0,0 +1,25 @@
1
+ (tag_name) @keyword
2
+ (param_tag "@param" @keyword)
3
+ (returns_tag ["@returns" "@return"] @keyword)
4
+ (template_tag "@template" @keyword)
5
+ (typedef_tag "@typedef" @keyword)
6
+ (type_tag "@type" @keyword)
7
+ (throws_tag ["@throws" "@throw"] @keyword)
8
+ (deprecated_tag "@deprecated" @keyword)
9
+ (since_tag "@since" @keyword)
10
+ (see_tag "@see" @keyword)
11
+ (example_tag "@example" @keyword)
12
+ (default_tag "@default" @keyword)
13
+
14
+ (type_param) @type.parameter
15
+ (type_identifier) @type
16
+ (primitive_type) @type.builtin
17
+ (any_type) @type.builtin
18
+ (module_type "module:" @module)
19
+ (module_path) @module
20
+
21
+ (identifier) @variable.parameter
22
+ (default_value) @constant
23
+ (description) @comment
24
+ (inline_tag "{" @punctuation.bracket "}" @punctuation.bracket)
25
+ (inline_tag (tag_name) @keyword)
@@ -0,0 +1,22 @@
1
+ (template_tag
2
+ (type_param) @template.param)
3
+
4
+ (param_tag
5
+ type: (_)? @param.type
6
+ name: (_)? @param.name
7
+ description: (description)? @param.description)
8
+
9
+ (returns_tag
10
+ type: (type_expression) @returns.type
11
+ description: (description)? @returns.description)
12
+
13
+ (throws_tag
14
+ type: (type_expression)? @throws.type
15
+ description: (description)? @throws.description)
16
+
17
+ (typedef_tag
18
+ type: (type_expression)? @typedef.type
19
+ name: (type_identifier) @typedef.name)
20
+
21
+ (type_tag
22
+ type: (type_expression) @type.type)