@repometry/language-scala 0.0.0-stage → 0.0.1
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/scala.d.ts +2 -0
- package/target/main/ts/scala.js +99 -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-scala",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Scala 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
|
+
"scala"
|
|
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.6.0",
|
|
42
|
+
"@repometry/tree-sitter": "0.5.0"
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"package": "tree-sitter-scala",
|
|
3
|
+
"version": "0.26.14",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"source": "https://github.com/tree-sitter/tree-sitter-scala/releases/download/v0.26.14/tree-sitter-scala.wasm",
|
|
6
|
+
"sha256": "ad2a586a7f8d0ef83b4d2d51bbb06ab1e79e509bc2c81c8accb78f25fa295f3b"
|
|
7
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2018 Max Brunsfeld and GitHub
|
|
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 { scala } from './scala.js';
|
|
2
|
+
export { scala };
|
|
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,99 @@
|
|
|
1
|
+
import { measures } from '@repometry/tree-sitter';
|
|
2
|
+
import manifest from '../resources/grammar.json' with { type: 'json' };
|
|
3
|
+
const comments = new Set(['comment', 'block_comment']);
|
|
4
|
+
const cases = new Set(['case_block', 'indented_cases']);
|
|
5
|
+
const template = new Set(['template_body', 'with_template_body']);
|
|
6
|
+
const templateBody = (node) => node.namedChildren.filter(child => template.has(child.type));
|
|
7
|
+
const declaredBody = (node) => node.childrenForFieldName('body');
|
|
8
|
+
const partialFunction = { flow: 'function', body: partialBody, requiresBody: true, parameters: () => 1 };
|
|
9
|
+
const namedClass = { flow: 'class', body: declaredBody };
|
|
10
|
+
function methodParameters(node) {
|
|
11
|
+
// An extension group's header supplies the same value and using parameters to each of its methods.
|
|
12
|
+
const extension = node.parent;
|
|
13
|
+
return parameterClauses(node) + (extension?.type === 'extension_definition' ? parameterClauses(extension) : 0);
|
|
14
|
+
}
|
|
15
|
+
function parameterClauses(node) {
|
|
16
|
+
return node.childrenForFieldName('parameters').reduce((count, clause) => count + (clause.type === 'parameters'
|
|
17
|
+
? clause.namedChildren.filter(child => child.type !== 'erased_modifier' && !comments.has(child.type)).length : 0), 0);
|
|
18
|
+
}
|
|
19
|
+
function lambdaParameters(node) {
|
|
20
|
+
const parameter = node.childrenForFieldName('parameters').find(child => child.isNamed);
|
|
21
|
+
if (parameter?.type === 'bindings')
|
|
22
|
+
return parameter.namedChildren.filter(child => child.type === 'binding').length;
|
|
23
|
+
return Number(parameter !== undefined);
|
|
24
|
+
}
|
|
25
|
+
function lambdaBody(node) {
|
|
26
|
+
const header = new Set([...node.childrenForFieldName('parameters'), ...node.childrenForFieldName('type_parameters')]
|
|
27
|
+
.map(child => child.id));
|
|
28
|
+
return node.namedChildren.filter(child => !header.has(child.id) && !comments.has(child.type));
|
|
29
|
+
}
|
|
30
|
+
function partialBody(node) {
|
|
31
|
+
// Case blocks in a match or catch are branches of that expression. Elsewhere they define a callable.
|
|
32
|
+
const owner = node.parent?.type;
|
|
33
|
+
return owner === 'match_expression' || owner === 'catch_clause'
|
|
34
|
+
? [] : node.namedChildren.filter(child => child.type === 'case_clause');
|
|
35
|
+
}
|
|
36
|
+
function caseDecision(node) {
|
|
37
|
+
if (node.parent?.parent?.type === 'catch_clause')
|
|
38
|
+
return 1;
|
|
39
|
+
let pattern = node.childForFieldName('pattern');
|
|
40
|
+
while (pattern?.type === 'capture_pattern')
|
|
41
|
+
pattern = pattern.childForFieldName('pattern');
|
|
42
|
+
const catchAll = pattern?.type === 'wildcard' || (pattern?.type === 'identifier' && /^\p{Ll}/u.test(pattern.text));
|
|
43
|
+
return Number(!catchAll);
|
|
44
|
+
}
|
|
45
|
+
const tokens = {
|
|
46
|
+
candidates: new Set([
|
|
47
|
+
'assignment_expression', 'block', 'call_expression', 'case_block', 'case_clause', 'catch_clause',
|
|
48
|
+
'class_definition', 'colon_argument', 'do_while_expression', 'enum_body', 'enum_definition', 'enumerators',
|
|
49
|
+
'extension_definition', 'finally_clause', 'for_expression', 'function_definition', 'given_definition',
|
|
50
|
+
'if_expression', 'indented_block', 'indented_cases', 'instance_expression', 'lambda_expression', 'match_expression',
|
|
51
|
+
'object_definition', 'package_object', 'return_expression', 'template_body', 'throw_expression', 'trait_definition',
|
|
52
|
+
'try_expression', 'tuple_expression', 'type_definition', 'val_definition', 'var_definition', 'while_expression',
|
|
53
|
+
'with_template_body',
|
|
54
|
+
]),
|
|
55
|
+
kinds: new Map([
|
|
56
|
+
['identifier', 'identifier'], ['type_identifier', 'identifier'], ['integer_literal', 'integer'],
|
|
57
|
+
['floating_point_literal', 'float'], ['character_literal', 'character'], ['string', 'string'],
|
|
58
|
+
['boolean_literal', 'boolean'], ['null_literal', 'null'], ['interpolated_string', 'interpolated-string'],
|
|
59
|
+
]),
|
|
60
|
+
// The AST skips raw text between substitutions; preserve the literal's entire spelling as one token.
|
|
61
|
+
literalsWithComments: new Set(['interpolated_string']),
|
|
62
|
+
};
|
|
63
|
+
export const scala = {
|
|
64
|
+
language: { id: 'scala', label: 'Scala', color: '#c22d40', extensions: ['.scala'], measures: [...measures, 'classes'] },
|
|
65
|
+
tool: { package: manifest.package, version: manifest.version },
|
|
66
|
+
asset: new URL('../resources/tree-sitter.wasm', import.meta.url),
|
|
67
|
+
prepareSource: text => text,
|
|
68
|
+
columns: 'codepoints',
|
|
69
|
+
name: node => node.childForFieldName('name')?.text,
|
|
70
|
+
rules: {
|
|
71
|
+
function_definition: { flow: 'function', parameters: methodParameters },
|
|
72
|
+
lambda_expression: { flow: 'function', body: lambdaBody, parameters: lambdaParameters },
|
|
73
|
+
case_block: partialFunction,
|
|
74
|
+
indented_cases: partialFunction,
|
|
75
|
+
class_definition: namedClass,
|
|
76
|
+
trait_definition: namedClass,
|
|
77
|
+
object_definition: namedClass,
|
|
78
|
+
package_object: namedClass,
|
|
79
|
+
enum_definition: { flow: 'class' },
|
|
80
|
+
instance_expression: { flow: 'class', body: templateBody, requiresBody: true },
|
|
81
|
+
given_definition: { flow: 'class', body: templateBody, requiresBody: true },
|
|
82
|
+
if_expression: { flow: 'if', decision: true },
|
|
83
|
+
indented_block: { chainedAlternative: true },
|
|
84
|
+
while_expression: { flow: 'nest', decision: true },
|
|
85
|
+
do_while_expression: { flow: 'nest', decision: true },
|
|
86
|
+
for_expression: { flow: 'nest' },
|
|
87
|
+
enumerator: { decision: node => Number(node.children.some(child => child.type === '<-' || child.type === '←')) },
|
|
88
|
+
guard: { flow: 'nest', decision: true },
|
|
89
|
+
match_expression: { flow: 'nest' },
|
|
90
|
+
case_clause: { decision: caseDecision },
|
|
91
|
+
catch_clause: { flow: 'nest', decision: node => Number(!node.namedChildren.some(child => cases.has(child.type))) },
|
|
92
|
+
return_expression: { exit: 'return' },
|
|
93
|
+
},
|
|
94
|
+
parens: new Set(['parenthesized_expression']), comments, extras: new Set(),
|
|
95
|
+
logicalTypes: new Set(['infix_expression']), logicalOperators: new Set(['&&', '||']),
|
|
96
|
+
logicalOperatorSpelling: true, logicalCognitive: 'sequence',
|
|
97
|
+
moduleDepthLabel: 'Module · Control-flow depth', tokens,
|
|
98
|
+
};
|
|
99
|
+
//# sourceMappingURL=scala.js.map
|
package/README.md
DELETED