@repometry/language-kotlin 0.0.0-stage → 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 +21 -0
- package/package.json +42 -4
- package/target/main/resources/grammar.json +7 -0
- package/target/main/resources/tree-sitter.LICENSE +21 -0
- package/target/main/resources/tree-sitter.wasm +0 -0
- package/target/main/ts/index.d.ts +7 -0
- package/target/main/ts/index.js +5 -0
- package/target/main/ts/kotlin.d.ts +2 -0
- package/target/main/ts/kotlin.js +90 -0
- package/README.md +0 -3
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,6 +1,44 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@repometry/language-kotlin",
|
|
3
|
-
"version": "0.0.0
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "Kotlin for the Repometry tree-sitter plugin, with its grammar",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/idleware/repometry.git"
|
|
9
|
+
},
|
|
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
|
+
"kotlin"
|
|
18
|
+
],
|
|
19
|
+
"type": "module",
|
|
20
|
+
"engines": {
|
|
21
|
+
"node": ">=24"
|
|
22
|
+
},
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"types": "./target/main/ts/index.d.ts",
|
|
26
|
+
"default": "./target/main/ts/index.js"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"files": [
|
|
30
|
+
"target/main",
|
|
31
|
+
"!target/main/**/*.map"
|
|
32
|
+
],
|
|
33
|
+
"publishConfig": {
|
|
34
|
+
"access": "public"
|
|
35
|
+
},
|
|
36
|
+
"scripts": {
|
|
37
|
+
"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')\"",
|
|
38
|
+
"prepack": "npm run build"
|
|
39
|
+
},
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"@repometry/core": "0.2.0",
|
|
42
|
+
"@repometry/tree-sitter": "0.1.0"
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"package": "@tree-sitter-grammars/tree-sitter-kotlin",
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"integrity": "sha512-vlVXaxEE8t2kpJgfZpa8XVvxcnKw9AYtRTgy7KWjsDmAsadk06RxAT80IXOgGQnmM9i/orQn1nD84gPNUHu6DQ==",
|
|
6
|
+
"sha256": "7009d69453bc8735e438b2818a633efb21c88f99782769abba60dffedfab73f7"
|
|
7
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Amaan Qureshi <amaanq12@gmail.com>
|
|
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.
|
|
Binary file
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { kotlin } from './kotlin.js';
|
|
2
|
+
export { kotlin };
|
|
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,90 @@
|
|
|
1
|
+
import { measures } from '@repometry/tree-sitter';
|
|
2
|
+
import manifest from '../resources/grammar.json' with { type: 'json' };
|
|
3
|
+
const comments = new Set(['line_comment', 'block_comment', 'shebang']);
|
|
4
|
+
const functionBody = (node) => node.namedChildren.filter(child => child.type === 'function_body');
|
|
5
|
+
const classBody = (node) => node.namedChildren.filter(child => child.type === 'class_body' || child.type === 'enum_class_body');
|
|
6
|
+
const constructorBody = (node) => node.namedChildren.filter(child => child.type === 'block' || child.type === 'constructor_delegation_call');
|
|
7
|
+
const lambdaBody = (node) => node.namedChildren.filter(child => child.type !== 'lambda_parameters' && !comments.has(child.type));
|
|
8
|
+
function functionParameters(node) {
|
|
9
|
+
// The list also contains parameter modifiers and default expressions as separate children.
|
|
10
|
+
const parameters = node.namedChildren.find(child => child.type === 'function_value_parameters');
|
|
11
|
+
return parameters?.namedChildren.filter(child => child.type === 'parameter').length ?? 0;
|
|
12
|
+
}
|
|
13
|
+
function lambdaParameters(node) {
|
|
14
|
+
const parameters = node.namedChildren.find(child => child.type === 'lambda_parameters');
|
|
15
|
+
return parameters?.namedChildren.filter(child => child.type === 'variable_declaration' || child.type === 'multi_variable_declaration').length ?? 0;
|
|
16
|
+
}
|
|
17
|
+
function alternative(node) {
|
|
18
|
+
const children = node.children;
|
|
19
|
+
const index = children.findIndex(child => child.type === 'else');
|
|
20
|
+
return index < 0 ? null : children.slice(index + 1).find(child => !comments.has(child.type)) ?? null;
|
|
21
|
+
}
|
|
22
|
+
function name(node) {
|
|
23
|
+
const declared = node.childForFieldName('name')?.text;
|
|
24
|
+
if (declared)
|
|
25
|
+
return declared;
|
|
26
|
+
switch (node.type) {
|
|
27
|
+
case 'companion_object': return 'Companion';
|
|
28
|
+
case 'secondary_constructor': return 'constructor';
|
|
29
|
+
case 'getter':
|
|
30
|
+
case 'setter': {
|
|
31
|
+
const property = node.parent?.namedChildren.find(child => child.type === 'variable_declaration');
|
|
32
|
+
const identifier = property?.namedChildren.find(child => child.type === 'identifier')?.text;
|
|
33
|
+
return identifier ? identifier + (node.type === 'getter' ? '.get' : '.set') : undefined;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const tokens = {
|
|
38
|
+
candidates: new Set(['anonymous_function', 'anonymous_initializer', 'assignment', 'block', 'call_expression',
|
|
39
|
+
'catch_block', 'class_body', 'class_declaration', 'companion_object', 'do_while_statement',
|
|
40
|
+
'enum_class_body', 'finally_block', 'for_statement', 'function_body', 'function_declaration',
|
|
41
|
+
'getter', 'if_expression', 'lambda_literal', 'object_declaration', 'object_literal',
|
|
42
|
+
'property_declaration', 'return_expression', 'secondary_constructor', 'setter', 'throw_expression',
|
|
43
|
+
'try_expression', 'when_entry', 'when_expression', 'while_statement']),
|
|
44
|
+
kinds: new Map([
|
|
45
|
+
['identifier', 'identifier'], ['number_literal', 'integer'], ['float_literal', 'float'],
|
|
46
|
+
['character_literal', 'character'], ['string_content', 'string_content'],
|
|
47
|
+
]),
|
|
48
|
+
// The grammar gives these literal spellings the identifier node type.
|
|
49
|
+
normalize: (_type, text, kind) => [text, kind === 'identifier' ? literalKind(text) : kind],
|
|
50
|
+
};
|
|
51
|
+
function literalKind(text) {
|
|
52
|
+
switch (text) {
|
|
53
|
+
case 'true':
|
|
54
|
+
case 'false': return 'boolean';
|
|
55
|
+
case 'null': return 'null';
|
|
56
|
+
default: return 'identifier';
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
export const kotlin = {
|
|
60
|
+
language: { id: 'kotlin', label: 'Kotlin', color: '#a97bff', extensions: ['.kt', '.kts'], measures: [...measures, 'classes'] },
|
|
61
|
+
tool: { package: manifest.package, version: manifest.version },
|
|
62
|
+
asset: new URL('../resources/tree-sitter.wasm', import.meta.url),
|
|
63
|
+
prepareSource: text => text.replace(/\r(?!\n)/g, '\n'),
|
|
64
|
+
columns: 'codepoints', name,
|
|
65
|
+
rules: {
|
|
66
|
+
function_declaration: { flow: 'function', body: functionBody, parameters: functionParameters, requiresBody: true },
|
|
67
|
+
anonymous_function: { flow: 'function', body: functionBody, parameters: functionParameters, requiresBody: true },
|
|
68
|
+
lambda_literal: { flow: 'function', body: lambdaBody, parameters: lambdaParameters },
|
|
69
|
+
secondary_constructor: { flow: 'function', body: constructorBody, parameters: functionParameters },
|
|
70
|
+
getter: { flow: 'function', body: functionBody, requiresBody: true },
|
|
71
|
+
setter: { flow: 'function', body: functionBody, requiresBody: true, parameters: () => 1 },
|
|
72
|
+
class_declaration: { flow: 'class', body: classBody },
|
|
73
|
+
object_declaration: { flow: 'class', body: classBody },
|
|
74
|
+
companion_object: { flow: 'class', body: classBody },
|
|
75
|
+
object_literal: { flow: 'class', body: classBody },
|
|
76
|
+
if_expression: { flow: 'if', decision: true, alternative },
|
|
77
|
+
for_statement: { flow: 'nest', decision: true },
|
|
78
|
+
while_statement: { flow: 'nest', decision: true },
|
|
79
|
+
do_while_statement: { flow: 'nest', decision: true },
|
|
80
|
+
when_expression: { flow: 'nest' },
|
|
81
|
+
when_entry: { decision: node => Number(node.childForFieldName('condition') !== null) },
|
|
82
|
+
catch_block: { flow: 'nest', decision: true },
|
|
83
|
+
binary_expression: { decision: node => Number(node.childForFieldName('operator')?.type === '?:') },
|
|
84
|
+
return_expression: { exit: 'return' },
|
|
85
|
+
},
|
|
86
|
+
parens: new Set(['parenthesized_expression']), comments, extras: new Set(),
|
|
87
|
+
logicalTypes: new Set(['binary_expression']), logicalOperators: new Set(['&&', '||']), logicalCognitive: 'parent',
|
|
88
|
+
moduleDepthLabel: 'Module · Control-flow depth', tokens,
|
|
89
|
+
};
|
|
90
|
+
//# sourceMappingURL=kotlin.js.map
|
package/README.md
DELETED