Forked from mindstudio/big-rag
Project Files
src / parsers / bslParser.ts
import * as fs from "fs";
/**
* Parse BSL (Business Script Language) files for 1C:Enterprise
* BSL files contain source code in Russian (1C language)
*/
export async function parseBSL(filePath: string): Promise<string> {
try {
// BSL files are text files, read as UTF-8
// If UTF-8 fails, the error will be caught and handled
const content = await fs.promises.readFile(filePath, "utf-8");
// BSL files should preserve line breaks for code readability
// Remove excessive whitespace but keep structure
const cleaned = content
.replace(/\r\n?/g, "\n") // Normalize line endings
.replace(/[ \t]+/g, " ") // Collapse horizontal whitespace
.replace(/\n{3,}/g, "\n\n") // Keep paragraph separation
.trim();
return cleaned;
} catch (error) {
console.error(`Error parsing BSL file ${filePath}:`, error);
return "";
}
}