-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathconvertToASTpath.js
More file actions
30 lines (25 loc) · 925 Bytes
/
convertToASTpath.js
File metadata and controls
30 lines (25 loc) · 925 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// parseCtoToAst.js
import fs from 'fs';
import path from 'path';
import { Parser } from '@accordproject/concerto-cto';
function convertCTOToAST(ctoPath) {
try {
const absolutePath = path.resolve(ctoPath);
const dir = path.dirname(absolutePath);
const baseName = path.basename(absolutePath, '.cto');
const outFilePath = path.join(dir, `${baseName}.json`);
const modelContent = fs.readFileSync(absolutePath, 'utf8');
const ast = Parser.parse(modelContent, absolutePath);
fs.writeFileSync(outFilePath, JSON.stringify(ast, null, 2), 'utf8');
console.log(`✅ AST written to: ${outFilePath}`);
} catch (err) {
console.error(`❌ Failed to parse: ${ctoPath}`);
console.error(`Error: ${err.message}`);
}
}
const inputPath = process.argv[2];
if (!inputPath) {
console.error('❗ Usage: node parseCtoToAst.js <path/to/file.cto>');
process.exit(1);
}
convertCTOToAST(inputPath);