@repometry/language-c 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 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-c",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.0.0",
4
+ "description": "Experimental C and C headers 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
+ "c"
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-c",
3
+ "version": "0.24.2",
4
+ "license": "MIT",
5
+ "source": "https://github.com/tree-sitter/tree-sitter-c/releases/download/v0.24.2/tree-sitter-c.wasm",
6
+ "sha256": "83e8d7902b9d7f8c7c5cd4bd9acb5c7eb5faf42c09f85546b183964d3b5f48f9"
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.
@@ -0,0 +1,2 @@
1
+ import type { LanguageUnit as Grammar } from '@repometry/tree-sitter';
2
+ export declare const c: Grammar;
@@ -0,0 +1,78 @@
1
+ import { measures } from '@repometry/tree-sitter';
2
+ import manifest from '../resources/grammar.json' with { type: 'json' };
3
+ const comments = new Set(['comment']);
4
+ const typeDefinition = { flow: 'class', requiresBody: true };
5
+ const executableBlock = { flow: 'nest', decision: true };
6
+ function innerDeclarator(node) {
7
+ const child = node.childForFieldName('declarator');
8
+ if (child || node.type !== 'parenthesized_declarator' && node.type !== 'attributed_declarator')
9
+ return child;
10
+ return node.namedChildren.find(item => item.type === 'identifier' || item.type.endsWith('_declarator')) ?? null;
11
+ }
12
+ function name(node) {
13
+ if (node.type !== 'function_definition')
14
+ return node.childForFieldName('name')?.text;
15
+ for (let part = innerDeclarator(node); part; part = innerDeclarator(part)) {
16
+ if (part.type === 'identifier')
17
+ return part.text;
18
+ }
19
+ }
20
+ function parameterCount(node) {
21
+ let list = null;
22
+ // For a function returning a function pointer, the formal list closest to the name owns the definition.
23
+ for (let part = innerDeclarator(node); part; part = innerDeclarator(part)) {
24
+ if (part.type === 'function_declarator')
25
+ list = part.childForFieldName('parameters');
26
+ }
27
+ const parameters = list?.namedChildren.filter(child => child.type === 'parameter_declaration'
28
+ || child.type === 'variadic_parameter' || child.type === 'identifier') ?? [];
29
+ const [first, second] = parameters;
30
+ if (!second && first?.type === 'parameter_declaration' && !first.childForFieldName('declarator')
31
+ && first.childForFieldName('type')?.text === 'void')
32
+ return 0;
33
+ return parameters.length;
34
+ }
35
+ const tokens = {
36
+ candidates: new Set([
37
+ 'case_statement', 'compound_statement', 'conditional_expression', 'declaration', 'do_statement',
38
+ 'else_clause', 'enum_specifier', 'enumerator_list', 'expression_statement', 'field_declaration_list',
39
+ 'for_statement', 'function_definition', 'if_statement', 'initializer_list', 'labeled_statement',
40
+ 'preproc_elif', 'preproc_else', 'preproc_function_def', 'preproc_if', 'preproc_ifdef', 'return_statement',
41
+ 'struct_specifier', 'switch_statement', 'type_definition', 'union_specifier', 'while_statement',
42
+ ]),
43
+ kinds: new Map([
44
+ ['identifier', 'identifier'], ['field_identifier', 'identifier'], ['statement_identifier', 'identifier'],
45
+ ['type_identifier', 'identifier'], ['number_literal', 'number'], ['char_literal', 'character'],
46
+ ['string_literal', 'string'], ['true', 'boolean'], ['false', 'boolean'], ['null', 'null'], ['nullptr', 'null'],
47
+ ]),
48
+ };
49
+ export const c = {
50
+ language: { id: 'c', label: 'C', color: '#555555', extensions: ['.c', '.h'], measures: [...measures, 'classes'] },
51
+ tool: { package: manifest.package, version: manifest.version },
52
+ asset: new URL('../resources/tree-sitter.wasm', import.meta.url),
53
+ prepareSource: text => text,
54
+ lineBreaks: /\r\n|[\r\n]/g,
55
+ columns: 'codepoints', name,
56
+ recoverDeclarations: true,
57
+ ignoredFields: { preproc_if: 'condition', preproc_elif: 'condition' },
58
+ rules: {
59
+ function_definition: { flow: 'function', requiresBody: true, parameters: parameterCount },
60
+ struct_specifier: typeDefinition,
61
+ union_specifier: typeDefinition,
62
+ enum_specifier: typeDefinition,
63
+ if_statement: { flow: 'if', decision: true },
64
+ else_clause: { flow: 'else', chainedAlternative: true },
65
+ for_statement: executableBlock,
66
+ while_statement: executableBlock,
67
+ do_statement: executableBlock,
68
+ conditional_expression: executableBlock,
69
+ switch_statement: { flow: 'nest' },
70
+ case_statement: { decision: node => Number(node.firstChild?.type === 'case') },
71
+ goto_statement: { exit: 'label' },
72
+ return_statement: { exit: 'return' },
73
+ },
74
+ parens: new Set(['parenthesized_expression']), comments, extras: new Set(),
75
+ logicalTypes: new Set(['binary_expression']), logicalOperators: new Set(['&&', '||']), logicalCognitive: 'sequence',
76
+ moduleDepthLabel: 'Module · Control-flow depth', tokens,
77
+ };
78
+ //# sourceMappingURL=c.js.map
@@ -0,0 +1,7 @@
1
+ import { c } from './c.js';
2
+ export { c };
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 { c } from './c.js';
3
+ export { c };
4
+ export default treeSitter(c);
5
+ //# sourceMappingURL=index.js.map
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.