@repometry/language-cpp 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/cpp.d.ts +3 -0
- package/target/main/ts/cpp.js +137 -0
- package/target/main/ts/index.d.ts +5 -0
- package/target/main/ts/index.js +10 -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-cpp",
|
|
3
|
-
"version": "0.0.0
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "Experimental C++ for Repometry, with its tree-sitter 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
|
+
"cpp"
|
|
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.5.0",
|
|
42
|
+
"@repometry/tree-sitter": "0.4.0"
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"package": "tree-sitter-cpp",
|
|
3
|
+
"version": "0.23.4",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"source": "https://github.com/tree-sitter/tree-sitter-cpp/releases/download/v0.23.4/tree-sitter-cpp.wasm",
|
|
6
|
+
"sha256": "174eb0deb75b2ec7881bcacda9f995648d8e683956e5c2267e69ab6dc503fcbf"
|
|
7
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2014 Max Brunsfeld
|
|
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,137 @@
|
|
|
1
|
+
import { measures } from '@repometry/tree-sitter';
|
|
2
|
+
import manifest from '../resources/grammar.json' with { type: 'json' };
|
|
3
|
+
export const cppExtensions = ['.cc', '.cpp', '.cxx', '.hpp', '.hh'];
|
|
4
|
+
const comments = new Set(['comment']);
|
|
5
|
+
const types = new Set(['class_specifier', 'struct_specifier', 'union_specifier', 'enum_specifier']);
|
|
6
|
+
const functions = new Set(['function_definition', 'lambda_expression']);
|
|
7
|
+
const names = new Set([
|
|
8
|
+
'identifier', 'field_identifier', 'qualified_identifier', 'destructor_name',
|
|
9
|
+
'operator_name', 'operator_cast', 'template_function', 'template_method',
|
|
10
|
+
]);
|
|
11
|
+
const declaratorWrappers = new Set(['parenthesized_declarator', 'reference_declarator', 'attributed_declarator']);
|
|
12
|
+
const parameters = new Set([
|
|
13
|
+
'parameter_declaration', 'optional_parameter_declaration', 'variadic_parameter_declaration', 'variadic_parameter', '...',
|
|
14
|
+
]);
|
|
15
|
+
function innerDeclarator(node) {
|
|
16
|
+
const child = node.childForFieldName('declarator');
|
|
17
|
+
if (child || !declaratorWrappers.has(node.type))
|
|
18
|
+
return child;
|
|
19
|
+
return node.namedChildren.find(item => names.has(item.type) || item.type.endsWith('_declarator')) ?? null;
|
|
20
|
+
}
|
|
21
|
+
function parameterList(node) {
|
|
22
|
+
let list = null;
|
|
23
|
+
// The innermost function declarator owns the parameters when the return type is itself callable.
|
|
24
|
+
for (let part = node; part; part = innerDeclarator(part)) {
|
|
25
|
+
list = part.childForFieldName('parameters') ?? list;
|
|
26
|
+
}
|
|
27
|
+
return list;
|
|
28
|
+
}
|
|
29
|
+
function parameterCount(node) {
|
|
30
|
+
const declarator = innerDeclarator(node);
|
|
31
|
+
const entries = declarator && parameterList(declarator)?.children.filter(child => parameters.has(child.type));
|
|
32
|
+
const [first, second] = entries || [];
|
|
33
|
+
if (!second && first?.type === 'parameter_declaration' && !first.childForFieldName('declarator')
|
|
34
|
+
&& first.childForFieldName('type')?.text === 'void')
|
|
35
|
+
return 0;
|
|
36
|
+
return entries?.length ?? 0;
|
|
37
|
+
}
|
|
38
|
+
function declName(node) {
|
|
39
|
+
let tail = node;
|
|
40
|
+
while (tail.type === 'qualified_identifier') {
|
|
41
|
+
const member = tail.childForFieldName('name');
|
|
42
|
+
if (!member)
|
|
43
|
+
break;
|
|
44
|
+
tail = member;
|
|
45
|
+
}
|
|
46
|
+
const conversion = tail.type === 'operator_cast' ? parameterList(tail) : null;
|
|
47
|
+
return conversion ? node.text.slice(0, conversion.startIndex - node.startIndex).trimEnd() : node.text;
|
|
48
|
+
}
|
|
49
|
+
function writtenName(node) {
|
|
50
|
+
if (types.has(node.type))
|
|
51
|
+
return node.childForFieldName('name')?.text;
|
|
52
|
+
if (node.type !== 'function_definition')
|
|
53
|
+
return undefined;
|
|
54
|
+
for (let part = innerDeclarator(node); part; part = innerDeclarator(part)) {
|
|
55
|
+
if (names.has(part.type))
|
|
56
|
+
return declName(part);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function name(node) {
|
|
60
|
+
const written = writtenName(node);
|
|
61
|
+
if (!written || written.startsWith('::'))
|
|
62
|
+
return written;
|
|
63
|
+
const namespaces = [];
|
|
64
|
+
for (let parent = node.parent; parent; parent = parent.parent) {
|
|
65
|
+
if (types.has(parent.type) || functions.has(parent.type))
|
|
66
|
+
return written;
|
|
67
|
+
if (parent.type === 'namespace_definition') {
|
|
68
|
+
const qualifier = parent.childForFieldName('name')?.text;
|
|
69
|
+
if (qualifier)
|
|
70
|
+
namespaces.unshift(qualifier);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
const prefix = namespaces.join('::');
|
|
74
|
+
return !prefix || written.startsWith(prefix + '::') ? written : prefix + '::' + written;
|
|
75
|
+
}
|
|
76
|
+
function functionBody(node) {
|
|
77
|
+
const body = node.childForFieldName('body');
|
|
78
|
+
if (!body)
|
|
79
|
+
return node.type === 'function_definition' ? node.namedChildren.filter(child => child.type === 'try_statement') : [];
|
|
80
|
+
const initializers = node.namedChildren.find(child => child.type === 'field_initializer_list');
|
|
81
|
+
return initializers ? [initializers, body] : [body];
|
|
82
|
+
}
|
|
83
|
+
const classRule = { flow: 'class', requiresBody: true };
|
|
84
|
+
const functionRule = { flow: 'function', body: functionBody, requiresBody: true, parameters: parameterCount };
|
|
85
|
+
const blockRule = { flow: 'nest', decision: true };
|
|
86
|
+
const tokens = {
|
|
87
|
+
candidates: new Set([
|
|
88
|
+
...types, ...functions,
|
|
89
|
+
'case_statement', 'catch_clause', 'co_return_statement', 'compound_statement', 'conditional_expression',
|
|
90
|
+
'declaration', 'declaration_list', 'do_statement', 'else_clause', 'enumerator_list', 'expression_statement',
|
|
91
|
+
'field_declaration_list', 'field_initializer_list', 'for_range_loop', 'for_statement', 'if_statement',
|
|
92
|
+
'initializer_list', 'labeled_statement', 'namespace_definition', 'preproc_elif', 'preproc_else', 'preproc_function_def',
|
|
93
|
+
'preproc_if', 'preproc_ifdef', 'return_statement', 'switch_statement', 'template_declaration', 'throw_statement',
|
|
94
|
+
'try_statement', 'type_definition', 'while_statement',
|
|
95
|
+
]),
|
|
96
|
+
kinds: new Map([
|
|
97
|
+
['identifier', 'identifier'], ['field_identifier', 'identifier'], ['namespace_identifier', 'identifier'],
|
|
98
|
+
['statement_identifier', 'identifier'], ['type_identifier', 'identifier'], ['number_literal', 'number'],
|
|
99
|
+
['char_literal', 'character'], ['string_literal', 'string'], ['raw_string_literal', 'string'],
|
|
100
|
+
['true', 'boolean'], ['false', 'boolean'], ['null', 'null'], ['nullptr', 'null'],
|
|
101
|
+
]),
|
|
102
|
+
};
|
|
103
|
+
export const cpp = {
|
|
104
|
+
language: { id: 'cpp', label: 'C++', color: '#f34b7d', extensions: cppExtensions, measures: [...measures, 'classes'] },
|
|
105
|
+
tool: { package: manifest.package, version: manifest.version },
|
|
106
|
+
asset: new URL('../resources/tree-sitter.wasm', import.meta.url),
|
|
107
|
+
prepareSource: text => text,
|
|
108
|
+
lineBreaks: /\r\n|[\r\n]/g,
|
|
109
|
+
columns: 'codepoints', name,
|
|
110
|
+
recoverDeclarations: true,
|
|
111
|
+
ignoredFields: { preproc_if: 'condition', preproc_elif: 'condition' },
|
|
112
|
+
rules: {
|
|
113
|
+
function_definition: functionRule,
|
|
114
|
+
lambda_expression: functionRule,
|
|
115
|
+
class_specifier: classRule,
|
|
116
|
+
struct_specifier: classRule,
|
|
117
|
+
union_specifier: classRule,
|
|
118
|
+
enum_specifier: classRule,
|
|
119
|
+
if_statement: { flow: 'if', decision: true },
|
|
120
|
+
else_clause: { flow: 'else', chainedAlternative: true },
|
|
121
|
+
for_statement: blockRule,
|
|
122
|
+
for_range_loop: blockRule,
|
|
123
|
+
while_statement: blockRule,
|
|
124
|
+
do_statement: blockRule,
|
|
125
|
+
conditional_expression: blockRule,
|
|
126
|
+
catch_clause: blockRule,
|
|
127
|
+
switch_statement: { flow: 'nest' },
|
|
128
|
+
case_statement: { decision: node => Number(node.firstChild?.type === 'case') },
|
|
129
|
+
goto_statement: { exit: 'label' },
|
|
130
|
+
return_statement: { exit: 'return' },
|
|
131
|
+
co_return_statement: { exit: 'return' },
|
|
132
|
+
},
|
|
133
|
+
parens: new Set(['parenthesized_expression']), comments, extras: new Set(),
|
|
134
|
+
logicalTypes: new Set(['binary_expression']), logicalOperators: new Set(['&&', '||', 'and', 'or']), logicalCognitive: 'sequence',
|
|
135
|
+
moduleDepthLabel: 'Module · Control-flow depth', tokens,
|
|
136
|
+
};
|
|
137
|
+
//# sourceMappingURL=cpp.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { treeSitter } from '@repometry/tree-sitter';
|
|
2
|
+
import { cpp, cppExtensions } from './cpp.js';
|
|
3
|
+
export { cpp };
|
|
4
|
+
// The runtime accepts .h after an explicit include, while the manifest advertises only definite C++ suffixes.
|
|
5
|
+
const parser = treeSitter({ ...cpp, language: { ...cpp.language, extensions: [...cppExtensions, '.h'] } });
|
|
6
|
+
const manifest = { ...parser, languages: parser.languages?.map(language => ({
|
|
7
|
+
...language, include: language.include.filter(pattern => pattern !== '**/*.h'),
|
|
8
|
+
})) };
|
|
9
|
+
export default manifest;
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
package/README.md
DELETED