symbol-processor/src/map.ts

33 lines
970 B
TypeScript

import { Struct } from './struct';
import { ErrorOnLine, load } from './loader';
// Store Loaded Structures
const structures: {[id: string]: Struct} = {};
// Get Or Load Structure
export function getStructure(name: string) {
if (name in structures) {
// Already Loaded
return structures[name]!;
} else {
// Load Structure
try {
// Create Structure
const target = new Struct(name);
structures[name] = target;
// Parse File
load(target, name, false);
// Return
return target;
} catch (e) {
let error = e;
let extra = '';
if (e instanceof ErrorOnLine) {
extra = `${e.file}:${e.line}: `;
error = e.error;
}
console.log(`Error Loading ${name}: ${extra}${error instanceof Error ? error.stack : error}`);
process.exit(1);
}
}
}