mirror of
https://github.com/exogen/t2-mapper.git
synced 2026-02-25 01:23:57 +00:00
add TorqueScript transpiler and runtime
This commit is contained in:
parent
c8391a1056
commit
7d10fb7dee
49 changed files with 12324 additions and 2075 deletions
46
src/torqueScript/index.ts
Normal file
46
src/torqueScript/index.ts
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
import TorqueScript from "@/generated/TorqueScript.cjs";
|
||||
import { generate, type GeneratorOptions } from "./codegen";
|
||||
import type { Program } from "./ast";
|
||||
|
||||
export { generate, type GeneratorOptions } from "./codegen";
|
||||
export type { Program } from "./ast";
|
||||
export { createBuiltins } from "./builtins";
|
||||
export { createRuntime } from "./runtime";
|
||||
export { normalizePath } from "./utils";
|
||||
export type {
|
||||
BuiltinsContext,
|
||||
BuiltinsFactory,
|
||||
RuntimeState,
|
||||
TorqueObject,
|
||||
TorqueRuntime,
|
||||
TorqueRuntimeOptions,
|
||||
} from "./types";
|
||||
|
||||
export interface ParseOptions {
|
||||
filename?: string;
|
||||
}
|
||||
|
||||
export type TranspileOptions = ParseOptions & GeneratorOptions;
|
||||
|
||||
export function parse(source: string, options?: ParseOptions): Program {
|
||||
try {
|
||||
return TorqueScript.parse(source);
|
||||
} catch (error: any) {
|
||||
if (options?.filename && error.location) {
|
||||
throw new Error(
|
||||
`${options.filename}:${error.location.start.line}:${error.location.start.column}: ${error.message}`,
|
||||
{ cause: error },
|
||||
);
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
export function transpile(
|
||||
source: string,
|
||||
options?: TranspileOptions,
|
||||
): { code: string; ast: Program } {
|
||||
const ast = parse(source, options);
|
||||
const code = generate(ast, options);
|
||||
return { code, ast };
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue