silverbullet/common/languages.ts

127 lines
4.2 KiB
TypeScript
Raw Normal View History

import { LRLanguage } from "@codemirror/language";
import {
cLanguage,
cmakeLanguage,
cppLanguage,
csharpLanguage,
cssLanguage,
dartLanguage,
diffLanguage,
dockerfileLanguage,
goLanguage,
htmlLanguage,
javaLanguage,
javascriptLanguage,
jsonLanguage,
kotlinLanguage,
Language,
objectiveCLanguage,
objectiveCppLanguage,
perlLanguage,
postgresqlLanguage,
powerShellLanguage,
protobufLanguage,
pythonLanguage,
rustLanguage,
scalaLanguage,
shellLanguage,
sqlLanguage,
StreamLanguage,
tclLanguage,
tomlLanguage,
typescriptLanguage,
verilogLanguage,
vhdlLanguage,
xmlLanguage,
yamlLanguage,
} from "./deps.ts";
import {
extendedMarkdownLanguage,
highlightingExpressionParser,
highlightingQueryParser,
} from "./markdown_parser/parser.ts";
2023-10-04 23:14:24 +08:00
export const builtinLanguages: Record<string, Language> = {
"meta": StreamLanguage.define(yamlLanguage),
"yaml": StreamLanguage.define(yamlLanguage),
"include": StreamLanguage.define(yamlLanguage),
2023-10-04 23:14:24 +08:00
"embed": StreamLanguage.define(yamlLanguage),
"data": StreamLanguage.define(yamlLanguage),
"toc": StreamLanguage.define(yamlLanguage),
2023-10-04 23:14:24 +08:00
"javascript": javascriptLanguage,
"space-script": javascriptLanguage,
2023-10-04 23:14:24 +08:00
"js": javascriptLanguage,
"typescript": typescriptLanguage,
"ts": typescriptLanguage,
"sql": StreamLanguage.define(sqlLanguage),
"postgresql": StreamLanguage.define(postgresqlLanguage),
"pgsql": StreamLanguage.define(postgresqlLanguage),
"postgres": StreamLanguage.define(postgresqlLanguage),
"rust": StreamLanguage.define(rustLanguage),
"rs": StreamLanguage.define(rustLanguage),
"css": StreamLanguage.define(cssLanguage),
"space-style": StreamLanguage.define(cssLanguage),
2023-10-04 23:14:24 +08:00
"html": htmlLanguage,
"python": StreamLanguage.define(pythonLanguage),
"py": StreamLanguage.define(pythonLanguage),
"protobuf": StreamLanguage.define(protobufLanguage),
"proto": StreamLanguage.define(protobufLanguage),
"shell": StreamLanguage.define(shellLanguage),
"sh": StreamLanguage.define(shellLanguage),
"bash": StreamLanguage.define(shellLanguage),
"zsh": StreamLanguage.define(shellLanguage),
"fish": StreamLanguage.define(shellLanguage),
"swift": StreamLanguage.define(rustLanguage),
"toml": StreamLanguage.define(tomlLanguage),
"json": StreamLanguage.define(jsonLanguage),
"xml": StreamLanguage.define(xmlLanguage),
"c": StreamLanguage.define(cLanguage),
"cpp": StreamLanguage.define(cppLanguage),
"c++": StreamLanguage.define(cppLanguage),
"cxx": StreamLanguage.define(cppLanguage),
"java": StreamLanguage.define(javaLanguage),
"csharp": StreamLanguage.define(csharpLanguage),
"cs": StreamLanguage.define(csharpLanguage),
"c#": StreamLanguage.define(csharpLanguage),
"scala": StreamLanguage.define(scalaLanguage),
"kotlin": StreamLanguage.define(kotlinLanguage),
"objc": StreamLanguage.define(objectiveCLanguage),
"objective-c": StreamLanguage.define(objectiveCLanguage),
"objectivec": StreamLanguage.define(objectiveCLanguage),
"objcpp": StreamLanguage.define(objectiveCppLanguage),
"objective-cpp": StreamLanguage.define(objectiveCppLanguage),
"objectivecpp": StreamLanguage.define(objectiveCppLanguage),
"objective-c++": StreamLanguage.define(objectiveCppLanguage),
"objectivec++": StreamLanguage.define(objectiveCppLanguage),
"dart": StreamLanguage.define(dartLanguage),
2024-02-15 05:35:45 +08:00
"go": StreamLanguage.define(goLanguage),
"golang": StreamLanguage.define(goLanguage),
"diff": StreamLanguage.define(diffLanguage),
"powershell": StreamLanguage.define(powerShellLanguage),
"perl": StreamLanguage.define(perlLanguage),
"tcl": StreamLanguage.define(tclLanguage),
"verilog": StreamLanguage.define(verilogLanguage),
"vhdl": StreamLanguage.define(vhdlLanguage),
"dockerfile": StreamLanguage.define(dockerfileLanguage),
"cmake": StreamLanguage.define(cmakeLanguage),
2023-10-04 23:14:24 +08:00
"query": LRLanguage.define({
name: "query",
parser: highlightingQueryParser,
2023-10-04 23:14:24 +08:00
}),
"template": extendedMarkdownLanguage,
"expression": LRLanguage.define({
name: "expression",
parser: highlightingExpressionParser,
}),
2023-10-04 23:14:24 +08:00
};
export function languageFor(name: string): Language | null {
2023-10-04 23:14:24 +08:00
if (builtinLanguages[name]) {
return builtinLanguages[name];
}
2023-10-04 23:14:24 +08:00
if (name.startsWith("#")) {
return StreamLanguage.define(yamlLanguage);
}
return null;
}