silverbullet/common/syscalls/language.ts

24 lines
696 B
TypeScript
Raw Permalink Normal View History

2024-07-30 23:33:33 +08:00
import type { SysCallMapping } from "../../lib/plugos/system.ts";
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";
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);
},
"language.listLanguages": (): string[] => {
2023-10-04 23:14:24 +08:00
return Object.keys(builtinLanguages);
},
};
}