mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
move delarations to @hydrooj/common
This commit is contained in:
1 parent
100ccf718f
commit
4a33816a37
49 files changed
+496
-465
No files matched your search
@@ -0,0 +1,60 @@
|
||||
import yaml from 'js-yaml';
|
||||
|
||||
export interface LangConfig {
|
||||
disabled?: boolean;
|
||||
compile?: string;
|
||||
execute: string;
|
||||
code_file: string;
|
||||
highlight: string;
|
||||
monaco: string;
|
||||
time_limit_rate: number;
|
||||
memory_limit_rate: number;
|
||||
address_space_limit?: boolean;
|
||||
process_limit?: number;
|
||||
display: string;
|
||||
target?: string;
|
||||
key: string;
|
||||
hidden: boolean;
|
||||
isBinary?: boolean;
|
||||
analysis?: string;
|
||||
/** @deprecated */
|
||||
remote?: string;
|
||||
validAs?: Record<string, string>;
|
||||
/** @deprecated */
|
||||
pretest?: string | false;
|
||||
comment?: string | [string, string];
|
||||
compile_time_limit?: number;
|
||||
compile_memory_limit?: number;
|
||||
version?: string;
|
||||
}
|
||||
|
||||
export function parseLang(config: string): Record<string, LangConfig> {
|
||||
const file = yaml.load(config) as Record<string, LangConfig>;
|
||||
if (typeof file === 'undefined' || typeof file === 'string' || typeof file === 'number') throw new Error();
|
||||
for (const key of Object.keys(file)) if (key.startsWith('_')) delete file[key];
|
||||
for (const key in file) {
|
||||
const entry = file[key];
|
||||
if (key.includes('.')) {
|
||||
const base = key.split('.')[0];
|
||||
const baseCfg = file[base];
|
||||
for (const bkey in baseCfg || {}) {
|
||||
if (!(bkey in entry)) entry[bkey] = baseCfg[bkey];
|
||||
}
|
||||
}
|
||||
}
|
||||
for (const key in file) {
|
||||
const entry = file[key];
|
||||
entry.highlight ||= key;
|
||||
entry.monaco ||= entry.highlight;
|
||||
entry.time_limit_rate ||= 1;
|
||||
entry.memory_limit_rate ||= 1;
|
||||
entry.code_file ||= `foo.${key}`;
|
||||
entry.execute ||= '/w/foo';
|
||||
entry.key = key;
|
||||
entry.hidden ||= false;
|
||||
entry.disabled ||= false;
|
||||
entry.isBinary ||= false;
|
||||
entry.validAs ||= {};
|
||||
}
|
||||
return file;
|
||||
}
|
||||
Reference in new issue
Block a user