@repometry/language-swift 0.0.0-dev.0 → 0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Idleware
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/package.json CHANGED
@@ -1,14 +1,45 @@
1
1
  {
2
2
  "name": "@repometry/language-swift",
3
- "version": "0.0.0-dev.0",
4
- "description": "Reserved for Repometry: Swift language support. Not usable yet.",
3
+ "version": "0.0.0",
4
+ "description": "Standalone experimental Swift support for Repometry, with its tree-sitter grammar",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "git+https://github.com/idleware/repometry.git"
9
9
  },
10
10
  "homepage": "https://github.com/idleware/repometry#readme",
11
+ "bugs": {
12
+ "url": "https://github.com/idleware/repometry/issues"
13
+ },
14
+ "keywords": [
15
+ "repometry",
16
+ "tree-sitter",
17
+ "swift",
18
+ "experimental"
19
+ ],
20
+ "type": "module",
21
+ "engines": {
22
+ "node": ">=24"
23
+ },
24
+ "exports": {
25
+ ".": {
26
+ "types": "./target/main/ts/index.d.ts",
27
+ "default": "./target/main/ts/index.js"
28
+ }
29
+ },
30
+ "files": [
31
+ "target/main",
32
+ "!target/main/**/*.map"
33
+ ],
11
34
  "publishConfig": {
12
35
  "access": "public"
36
+ },
37
+ "scripts": {
38
+ "build": "node -e \"require('node:fs').rmSync('target/main', { recursive: true, force: true })\" && tsc -p tsconfig.json && node -e \"const fs = require('node:fs'); fs.cpSync('src/main/resources', 'target/main/resources', { recursive: true }); fs.cpSync('../../LICENSE', 'LICENSE')\"",
39
+ "prepack": "npm run build"
40
+ },
41
+ "dependencies": {
42
+ "@repometry/core": "0.5.0",
43
+ "@repometry/tree-sitter": "0.4.0"
13
44
  }
14
45
  }
@@ -0,0 +1,7 @@
1
+ {
2
+ "package": "tree-sitter-swift",
3
+ "version": "0.7.3",
4
+ "license": "MIT",
5
+ "source": "https://github.com/alex-pinkus/tree-sitter-swift/releases/download/0.7.3/tree-sitter-swift.wasm",
6
+ "sha256": "0258a7ef17303a8079ffe0748b3583d59656b5c3e8653fca7b6451b3e6689eb2"
7
+ }
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 alex-pinkus
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,7 @@
1
+ import { swift } from './swift.js';
2
+ export { swift };
3
+ declare const _default: import("@repometry/core").PluginManifest<import("@repometry/core/internal/model/plugin-data.js").JsonValue> & {
4
+ readonly version: string;
5
+ create(): Awaited<ReturnType<import("@repometry/core").PluginManifest['create']>>;
6
+ };
7
+ export default _default;
@@ -0,0 +1,5 @@
1
+ import { treeSitter } from '@repometry/tree-sitter';
2
+ import { swift } from './swift.js';
3
+ export { swift };
4
+ export default treeSitter(swift);
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,2 @@
1
+ import type { LanguageUnit as Grammar } from '@repometry/tree-sitter';
2
+ export declare const swift: Grammar;
@@ -0,0 +1,155 @@
1
+ import { measures } from '@repometry/tree-sitter';
2
+ import manifest from '../resources/grammar.json' with { type: 'json' };
3
+ const typeKinds = new Set(['actor', 'class', 'enum', 'struct']);
4
+ const accessors = new Map([['computed_getter', 'get'], ['computed_setter', 'set'], ['computed_modify', '_modify']]);
5
+ const functions = ['function_declaration', 'init_declaration', 'deinit_declaration'];
6
+ const loops = ['for_statement', 'while_statement', 'repeat_while_statement'];
7
+ const comments = new Set(['comment', 'multiline_comment']);
8
+ function typeKind(node) {
9
+ return node.childForFieldName('declaration_kind')?.type;
10
+ }
11
+ function completeType(node) {
12
+ const body = typeKinds.has(typeKind(node) ?? '') ? node.childForFieldName('body') : null;
13
+ return body ? [body] : [];
14
+ }
15
+ function statements(node) {
16
+ return node.namedChildren.filter(child => child.type === 'statements');
17
+ }
18
+ // The opening brace distinguishes an empty executable body from an accessor requirement.
19
+ function accessorBody(node) {
20
+ return node.children.filter(child => child.type === 'statements' || child.type === '{');
21
+ }
22
+ function implicitGetter(node) {
23
+ return node.namedChildren.some(child => accessors.has(child.type)) ? [] : accessorBody(node);
24
+ }
25
+ function accessorOwner(node) {
26
+ return node.type === 'computed_property' ? node.parent : node.parent?.parent;
27
+ }
28
+ function simpleName(node) {
29
+ if (node.type === 'lambda_literal')
30
+ return undefined;
31
+ if (node.type === 'init_declaration')
32
+ return 'init';
33
+ if (node.type === 'deinit_declaration')
34
+ return 'deinit';
35
+ const accessor = node.type === 'computed_property' ? 'get' : accessors.get(node.type);
36
+ if (accessor) {
37
+ const owner = accessorOwner(node);
38
+ const property = owner?.type === 'subscript_declaration' ? 'subscript' : owner?.childForFieldName('name')?.text;
39
+ return property && property + '.' + accessor;
40
+ }
41
+ return node.childForFieldName('name')?.text;
42
+ }
43
+ function name(node) {
44
+ const own = simpleName(node);
45
+ if (!own)
46
+ return undefined;
47
+ const names = [own];
48
+ for (let parent = node.parent; parent; parent = parent.parent) {
49
+ if (parent.type === 'class_declaration' && typeKind(parent) === 'extension') {
50
+ const extended = simpleName(parent);
51
+ if (extended)
52
+ names.unshift(extended);
53
+ continue;
54
+ }
55
+ const rule = rules[parent.type];
56
+ if (rule?.flow === 'class' || rule?.flow === 'function' &&
57
+ (!rule.requiresBody || (rule.body?.(parent).length ?? Number(parent.childForFieldName('body') !== null)) > 0))
58
+ break;
59
+ }
60
+ return names.join('.');
61
+ }
62
+ function parameters(node) {
63
+ return node.namedChildren.filter(child => child.type === 'parameter').length;
64
+ }
65
+ function closureParameters(node) {
66
+ const signature = node.childForFieldName('type');
67
+ const parameters = signature?.namedChildren.find(child => child.type === 'lambda_function_type_parameters');
68
+ return parameters?.namedChildren.filter(child => child.type === 'lambda_parameter').length ?? 0;
69
+ }
70
+ function accessorParameters(node) {
71
+ const owner = accessorOwner(node);
72
+ const indexes = owner?.type === 'subscript_declaration' ? parameters(owner) : 0;
73
+ return indexes + Number(node.type === 'computed_setter' && node.namedChildren.some(child => child.type === 'simple_identifier'));
74
+ }
75
+ function alternative(node) {
76
+ const children = node.children;
77
+ const marker = children.findIndex(child => child.type === 'else');
78
+ if (marker === -1)
79
+ return null;
80
+ return children.slice(marker + 1).find(child => child.isNamed && !comments.has(child.type)) ?? children[marker];
81
+ }
82
+ function extraConditions(node) {
83
+ return node.children.filter(child => child.type === ',').length;
84
+ }
85
+ function switchDecisions(node) {
86
+ const children = node.children;
87
+ return Number(children.some(child => child.type === 'case')) +
88
+ Number(children.some(child => child.type === 'where_keyword'));
89
+ }
90
+ const returns = { exit: 'return' };
91
+ const labeledJump = { exit: 'label' };
92
+ function transfer(node) {
93
+ const kind = node.firstChild?.type;
94
+ if (kind === 'return')
95
+ return returns;
96
+ if ((kind === 'break' || kind === 'continue') && node.childForFieldName('result'))
97
+ return labeledJump;
98
+ return undefined;
99
+ }
100
+ const rules = {
101
+ class_declaration: { flow: 'class', requiresBody: true, body: completeType },
102
+ protocol_declaration: { flow: 'class', requiresBody: true },
103
+ ...Object.fromEntries(functions.map(type => [type, { flow: 'function', requiresBody: true, parameters }])),
104
+ lambda_literal: { flow: 'function', body: statements, parameters: closureParameters },
105
+ computed_property: { flow: 'function', requiresBody: true, body: implicitGetter, parameters: accessorParameters },
106
+ ...Object.fromEntries([...accessors.keys()].map(type => [type,
107
+ { flow: 'function', requiresBody: true, body: accessorBody, parameters: accessorParameters }])),
108
+ ...Object.fromEntries(loops.map(type => [type, { flow: 'nest', decision: (node) => 1 + extraConditions(node) }])),
109
+ if_statement: { flow: 'if', decision: node => 1 + extraConditions(node), alternative },
110
+ guard_statement: { flow: 'nest', decision: node => 1 + extraConditions(node) },
111
+ switch_statement: { flow: 'nest' },
112
+ switch_entry: { decision: switchDecisions },
113
+ catch_block: { flow: 'nest', decision: true },
114
+ where_clause: { decision: node => Number(node.parent?.type === 'catch_block' || node.parent?.type === 'for_statement') },
115
+ ternary_expression: { flow: 'nest', decision: true },
116
+ nil_coalescing_expression: { decision: true },
117
+ control_transfer_statement: { select: transfer },
118
+ };
119
+ const tokens = {
120
+ candidates: new Set([
121
+ 'class_declaration', 'class_body', 'enum_class_body', 'protocol_declaration', 'protocol_body',
122
+ ...functions, ...loops, ...accessors.keys(),
123
+ 'function_body', 'lambda_literal', 'computed_property', 'property_declaration', 'subscript_declaration',
124
+ 'statements', 'if_statement', 'guard_statement', 'switch_statement', 'switch_entry', 'catch_block',
125
+ 'do_statement', 'assignment', 'call_expression', 'control_transfer_statement',
126
+ ]),
127
+ kinds: new Map([
128
+ ['simple_identifier', 'identifier'], ['type_identifier', 'identifier'],
129
+ ['integer_literal', 'integer'], ['bin_literal', 'integer'], ['hex_literal', 'integer'], ['oct_literal', 'integer'],
130
+ ['real_literal', 'float'], ['boolean_literal', 'boolean'],
131
+ ['line_str_text', 'string-fragment'], ['multi_line_str_text', 'string-fragment'],
132
+ ['str_escaped_char', 'string-fragment'], ['raw_str_part', 'raw-string-fragment'],
133
+ ['raw_str_end_part', 'raw-string-fragment'],
134
+ ]),
135
+ };
136
+ export const swift = {
137
+ language: { id: 'swift', label: 'Swift', color: '#f05138', extensions: ['.swift'], measures: [...measures, 'classes'] },
138
+ tool: { package: manifest.package, version: manifest.version },
139
+ asset: new URL('../resources/tree-sitter.wasm', import.meta.url),
140
+ prepareSource: text => text,
141
+ columns: 'codepoints',
142
+ name,
143
+ recoverDeclarations: true,
144
+ rules,
145
+ parens: new Set(['tuple_expression']),
146
+ comments,
147
+ extras: new Set(),
148
+ logicalTypes: new Set(['conjunction_expression', 'disjunction_expression']),
149
+ logicalOperators: new Set(['&&', '||']),
150
+ logicalOperatorSpelling: true,
151
+ logicalCognitive: 'sequence',
152
+ moduleDepthLabel: 'Module control-flow depth',
153
+ tokens,
154
+ };
155
+ //# sourceMappingURL=swift.js.map
package/README.md DELETED
@@ -1,4 +0,0 @@
1
- # @repometry/language-swift
2
-
3
- Reserved for [Repometry](https://github.com/idleware/repometry): Swift language support.
4
- This version is a placeholder with no code. Use the `repometry` package until a release appears here.