2024-07-30 23:33:33 +08:00
|
|
|
import type { SysCallMapping } from "../../lib/plugos/system.ts";
|
2023-10-03 20:16:33 +08:00
|
|
|
import { parse } from "../markdown_parser/parse_tree.ts";
|
2024-02-29 22:23:05 +08:00
|
|
|
import type { ParseTree } from "../../plug-api/lib/tree.ts";
|
2023-10-04 23:14:24 +08:00
|
|
|
import { builtinLanguages, languageFor } from "../languages.ts";
|
2023-10-03 20:16:33 +08:00
|
|
|
|
|
|
|
export function languageSyscalls(): SysCallMapping {
|
|
|
|
return {
|
|
|
|
"language.parseLanguage": (
|
|
|
|
_ctx,
|
|
|
|
language: string,
|
|
|
|
code: string,
|
|
|
|
): ParseTree => {
|
|
|
|
const lang = languageFor(language);
|
|
|
|
if (!lang) {
|
|
|
|
throw new Error(`Unknown language ${language}`);
|
|
|
|
}
|
|
|
|
return parse(lang, code);
|
|
|
|
},
|
2024-01-15 23:43:12 +08:00
|
|
|
"language.listLanguages": (): string[] => {
|
2023-10-04 23:14:24 +08:00
|
|
|
return Object.keys(builtinLanguages);
|
|
|
|
},
|
2023-10-03 20:16:33 +08:00
|
|
|
};
|
|
|
|
}
|