// Copyright (c) 2017, Compiler Explorer Authors
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
//     * Redistributions of source code must retain the above copyright notice,
//       this list of conditions and the following disclaimer.
//     * Redistributions in binary form must reproduce the above copyright
//       notice, this list of conditions and the following disclaimer in the
//       documentation and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.

import fs from 'node:fs';
import path from 'node:path';

import type {Language, LanguageKey} from '../types/languages.interfaces.js';

type DefKeys =
    | 'name'
    | 'monaco'
    | 'extensions'
    | 'alias'
    | 'previewFilter'
    | 'formatter'
    | 'logoFilename'
    | 'logoFilenameDark'
    | 'monacoDisassembly'
    | 'tooltip'
    | 'digitSeparator'
    | 'noAsmHint';
type LanguageDefinition = Pick<Language, DefKeys>;

const definitions: Record<LanguageKey, LanguageDefinition> = {
    jakt: {
        name: 'Jakt',
        monaco: 'jakt',
        extensions: ['.jakt'],
        alias: [],
        logoFilename: null,
        logoFilenameDark: null,
        formatter: null,
        previewFilter: null,
        monacoDisassembly: 'cppp',
    },
    'c++': {
        name: 'C++',
        monaco: 'cppp',
        extensions: ['.cpp', '.cxx', '.h', '.hpp', '.hxx', '.c', '.cc', '.ixx'],
        alias: ['gcc', 'cpp'],
        logoFilename: 'cpp.svg',
        logoFilenameDark: null,
        formatter: 'clangformat',
        previewFilter: /^\s*#include/,
        monacoDisassembly: null,
        digitSeparator: "'",
        noAsmHint:
            '# Tip: Inline or template functions may not generate code.\n' +
            '# Use __attribute__((noinline)) or instantiate templates explicitly.',
    },
    ada: {
        name: 'Ada',
        monaco: 'ada',
        extensions: ['.adb', '.ads'],
        alias: [],
        logoFilename: 'ada.svg',
        logoFilenameDark: 'ada-dark.svg',
        formatter: null,
        previewFilter: null,
        monacoDisassembly: null,
    },
    algol68: {
        name: 'Algol68',
        monaco: 'algol68',
        extensions: ['.a68'],
        alias: [],
        logoFilename: null,
        logoFilenameDark: null,
        formatter: null,
        previewFilter: null,
        monacoDisassembly: null,
    },
    analysis: {
        name: 'Analysis',
        monaco: 'asm',
        extensions: ['.asm'], // maybe add more? Change to a unique one?
        alias: ['tool', 'tools'],
        logoFilename: 'analysis.png', // TODO: Find a better alternative
        logoFilenameDark: null,
        formatter: null,
        previewFilter: null,
        monacoDisassembly: null,
        tooltip: 'A collection of asm analysis tools',
    },
    'android-java': {
        name: 'Android Java',
        monaco: 'java',
        extensions: ['.java'],
        alias: [],
        logoFilename: 'android.svg',
        logoFilenameDark: 'android-dark.svg',
        formatter: null,
        previewFilter: null,
        monacoDisassembly: null,
        digitSeparator: '_',
    },
    'android-kotlin': {
        name: 'Android Kotlin',
        monaco: 'kotlin',
        extensions: ['.kt'],
        alias: [],
        logoFilename: 'android.svg',
        logoFilenameDark: 'android-dark.svg',
        formatter: null,
        previewFilter: null,
        monacoDisassembly: null,
        digitSeparator: '_',
    },
    assembly: {
        name: 'Assembly',
        monaco: 'asm',
        extensions: ['.asm', '.6502', '.s'],
        alias: ['asm'],
        logoFilename: 'assembly.png', // TODO: Find a better alternative
        logoFilenameDark: null,
        formatter: null,
        previewFilter: null,
        monacoDisassembly: null,
    },
    c: {
        name: 'C',
        monaco: 'nc',
        extensions: ['.c', '.h'],
        alias: [],
        logoFilename: 'c.svg',
        logoFilenameDark: null,
        formatter: 'clangformat',
        previewFilter: /^\s*#include/,
        monacoDisassembly: null,
        digitSeparator: "'",
    },
    c3: {
        name: 'C3',
        monaco: 'c3',
        extensions: ['.c3'],
        alias: [],
        logoFilename: 'c3.svg',
        logoFilenameDark: null,
        formatter: null,
        previewFilter: null,
        monacoDisassembly: null,
    },
    carbon: {
        name: 'Carbon',
        monaco: 'carbon',
        extensions: ['.carbon'],
        alias: [],
        logoFilename: 'carbon.png',
        logoFilenameDark: null,
        formatter: null,
        previewFilter: null,
        monacoDisassembly: null,
    },
    coccinelle_for_c: {
        name: 'C with Coccinelle',
        monaco: 'nc',
        extensions: ['.c', '.h'],
        alias: [],
        logoFilename: 'c.svg',
        logoFilenameDark: null,
        formatter: 'clangformat',
        previewFilter: /^\s*#include/,
        monacoDisassembly: null,
        digitSeparator: "'",
    },
    coccinelle_for_cpp: {
        name: 'C++ with Coccinelle',
        monaco: 'cppp',
        extensions: ['.cpp', '.h'],
        alias: [],
        logoFilename: 'cpp.svg',
        logoFilenameDark: null,
        formatter: 'clangformat',
        previewFilter: /^\s*#include/,
        monacoDisassembly: null,
        digitSeparator: "'",
    },
    circle: {
        name: 'C++ (Circle)',
        monaco: 'cppcircle',
        extensions: ['.cpp', '.cxx', '.h', '.hpp', '.hxx', '.c'],
        alias: [],
        previewFilter: /^\s*#include/,
        logoFilename: 'cpp.svg', // TODO: Find a better alternative
        logoFilenameDark: null,
        formatter: null,
        monacoDisassembly: null,
        digitSeparator: "'",
    },
    circt: {
        name: 'CIRCT',
        monaco: 'mlir',
        extensions: ['.mlir'],
        alias: [],
        logoFilename: 'circt.svg',
        formatter: null,
        logoFilenameDark: null,
        previewFilter: null,
        monacoDisassembly: 'mlir',
    },
    clean: {
        name: 'Clean',
        monaco: 'clean',
        extensions: ['.icl'],
        alias: [],
        logoFilename: 'clean.svg', // TODO: Find a better alternative
        logoFilenameDark: null,
        formatter: null,
        previewFilter: null,
        monacoDisassembly: null,
    },
    clojure: {
        name: 'Clojure',
        monaco: 'clojure',
        extensions: ['.clj'],
        alias: [],
        logoFilename: 'clojure.svg',
        logoFilenameDark: null,
        formatter: null,
        previewFilter: null,
        monacoDisassembly: null,
    },
    co2: {
        name: 'CO2',
        monaco: 'co2',
        extensions: ['.co2', '.c'],
        alias: [],
        logoFilename: null,
        logoFilenameDark: null,
        formatter: 'co2fmt',
        previewFilter: /^\s*#include/,
        monacoDisassembly: null,
        digitSeparator: '_',
    },
    cmake: {
        name: 'CMake',
        monaco: 'cmake',
        extensions: ['.txt'],
        alias: [],
        logoFilename: 'cmake.svg',
        logoFilenameDark: null,
        formatter: null,
        previewFilter: null,
        monacoDisassembly: null,
    },
    cmakescript: {
        name: 'CMakeScript',
        monaco: 'cmake',
        extensions: ['.cmake'],
        alias: [],
        logoFilename: 'cmake.svg',
        logoFilenameDark: null,
        formatter: null,
        previewFilter: null,
        monacoDisassembly: null,
    },
    cobol: {
        name: 'COBOL',
        monaco: 'cobol',
        extensions: ['.cob', '.cbl', '.cobol'],
        alias: [],
        logoFilename: null, // TODO: Find a better alternative
        formatter: null,
        logoFilenameDark: null,
        previewFilter: null,
        monacoDisassembly: null,
    },
    cpp_for_opencl: {
        name: 'C++ for OpenCL',
        monaco: 'cpp-for-opencl',
        extensions: ['.clcpp', '.cl', '.ocl'],
        alias: [],
        logoFilename: 'opencl.svg', // TODO: Find a better alternative
        logoFilenameDark: 'opencl-dark.svg',
        formatter: null,
        previewFilter: null,
        monacoDisassembly: null,
        digitSeparator: "'",
    },
    mlir: {
        name: 'MLIR',
        monaco: 'mlir',
        extensions: ['.mlir'],
        alias: [],
        logoFilename: 'mlir.svg',
        formatter: null,
        logoFilenameDark: null,
        previewFilter: null,
        monacoDisassembly: null,
    },
    cppx: {
        name: 'Cppx',
        monaco: 'cppp',
        extensions: ['.cpp', '.cxx', '.h', '.hpp', '.hxx', '.c'],
        alias: [],
        logoFilename: 'cpp.svg',
        logoFilenameDark: null,
        formatter: null,
        previewFilter: /^\s*#include/,
        monacoDisassembly: null,
        digitSeparator: "'",
    },
    cppx_blue: {
        name: 'Cppx-Blue',
        monaco: 'cppx-blue',
        extensions: ['.blue', '.cpp', '.cxx', '.h', '.hpp', '.hxx', '.c'],
        alias: [],
        logoFilename: 'cpp.svg', // TODO: Find a better alternative
        logoFilenameDark: null,
        formatter: null,
        previewFilter: null,
        monacoDisassembly: null,
    },
    cppx_gold: {
        name: 'Cppx-Gold',
        monaco: 'cppx-gold',
        extensions: ['.usyntax', '.cpp', '.cxx', '.h', '.hpp', '.hxx', '.c'],
        alias: [],
        logoFilename: 'cpp.svg', // TODO: Find a better alternative
        logoFilenameDark: null,
        formatter: null,
        previewFilter: null,
        monacoDisassembly: null,
        digitSeparator: "'",
    },
    cpp2_cppfront: {
        name: 'Cpp2-cppfront',
        monaco: 'cpp2-cppfront',
        extensions: ['.cpp2'],
        alias: [],
        logoFilename: 'cpp.svg', // TODO: Find a better alternative
        logoFilenameDark: null,
        formatter: null,
        previewFilter: null,
        monacoDisassembly: 'cppp',
        digitSeparator: "'",
    },
    crystal: {
        name: 'Crystal',
        monaco: 'crystal',
        extensions: ['.cr'],
        alias: [],
        logoFilename: 'crystal.svg',
        logoFilenameDark: 'crystal-dark.svg',
        formatter: null,
        previewFilter: null,
        monacoDisassembly: null,
        digitSeparator: '_',
    },
    csharp: {
        name: 'C#',
        monaco: 'csharp',
        extensions: ['.cs'],
        alias: [],
        logoFilename: 'dotnet.svg',
        logoFilenameDark: null,
        formatter: 'clangformat',
        previewFilter: null,
        monacoDisassembly: null,
        digitSeparator: '_',
    },
    cuda: {
        name: 'CUDA C++',
        monaco: 'cuda',
        extensions: ['.cu', '.cuh'],
        alias: ['nvcc', 'scale-nvcc-nvidia', 'scale-nvcc-amd'],
        logoFilename: 'cuda.svg',
        logoFilenameDark: 'cuda-dark.svg',
        formatter: 'clangformat',
        previewFilter: null,
        monacoDisassembly: null,
        digitSeparator: "'",
    },
    cutedsl: {
        name: 'CuTe DSL',
        monaco: 'python',
        extensions: ['.py'],
        alias: ['cute', 'cutlass-cute', 'cutlass-cute-dsl'],
        logoFilename: null,
        logoFilenameDark: null,
        formatter: null,
        previewFilter: null,
        monacoDisassembly: 'ptx',
    },
    d: {
        name: 'D',
        monaco: 'd',
        extensions: ['.d'],
        alias: [],
        logoFilename: 'd.svg',
        logoFilenameDark: null,
        formatter: null,
        previewFilter: null,
        monacoDisassembly: null,
    },
    dart: {
        name: 'Dart',
        monaco: 'dart',
        extensions: ['.dart'],
        alias: [],
        logoFilename: 'dart.svg',
        logoFilenameDark: null,
        formatter: 'dartformat',
        previewFilter: null,
        monacoDisassembly: null,
    },
    elixir: {
        name: 'Elixir',
        monaco: 'elixir',
        extensions: ['.ex'],
        alias: [],
        logoFilename: 'elixir.svg',
        logoFilenameDark: null,
        formatter: null,
        previewFilter: null,
        monacoDisassembly: null,
    },
    erlang: {
        name: 'Erlang',
        monaco: 'erlang',
        extensions: ['.erl', '.hrl'],
        alias: [],
        logoFilename: 'erlang.svg',
        logoFilenameDark: null,
        formatter: null,
        previewFilter: null,
        monacoDisassembly: null,
    },
    fortran: {
        name: 'Fortran',
        monaco: 'fortran',
        extensions: ['.f90', '.F90', '.f95', '.F95', '.f'],
        alias: [],
        logoFilename: 'fortran.svg',
        logoFilenameDark: null,
        formatter: null,
        previewFilter: null,
        monacoDisassembly: null,
    },
    fsharp: {
        name: 'F#',
        monaco: 'fsharp',
        extensions: ['.fs'],
        alias: [],
        logoFilename: 'fsharp.svg',
        logoFilenameDark: null,
        formatter: null,
        previewFilter: null,
        monacoDisassembly: null,
    },
    glsl: {
        name: 'GLSL',
        monaco: 'glsl',
        extensions: ['.glsl'],
        alias: [],
        logoFilename: 'glsl.svg',
        logoFilenameDark: 'glsl-dark.svg',
        formatter: null,
        previewFilter: null,
        monacoDisassembly: null,
    },
    go: {
        name: 'Go',
        monaco: 'go',
        extensions: ['.go'],
        alias: [],
        logoFilename: 'go.svg',
        logoFilenameDark: null,
        formatter: 'gofmt',
        previewFilter: null,
        monacoDisassembly: null,
        digitSeparator: '_',
    },
    haskell: {
        name: 'Haskell',
        monaco: 'haskell',
        extensions: ['.hs', '.haskell'],
        alias: [],
        logoFilename: 'haskell.png',
        logoFilenameDark: null,
        formatter: null,
        previewFilter: null,
        monacoDisassembly: null,
        digitSeparator: '_',
    },
    hlsl: {
        name: 'HLSL',
        monaco: 'hlsl',
        extensions: ['.hlsl', '.hlsli'],
        alias: [],
        logoFilename: 'hlsl.png',
        logoFilenameDark: null,
        formatter: null,
        previewFilter: null,
        monacoDisassembly: null,
    },
    helion: {
        name: 'Helion',
        monaco: 'python',
        extensions: ['.py'],
        alias: [],
        logoFilename: 'helion.png',
        logoFilenameDark: 'helion.png',
        formatter: null,
        previewFilter: null,
        monacoDisassembly: null,
        digitSeparator: '_',
    },
    hook: {
        name: 'Hook',
        monaco: 'hook',
        extensions: ['.hk', '.hook'],
        alias: [],
        logoFilename: 'hook.png',
        logoFilenameDark: 'hook-dark.png',
        formatter: null,
        previewFilter: null,
        monacoDisassembly: null,
    },
    hylo: {
        name: 'Hylo',
        monaco: 'hylo',
        extensions: ['.hylo'],
        alias: [],
        logoFilename: 'hylo.png',
        logoFilenameDark: null,
        formatter: null,
        previewFilter: null,
        monacoDisassembly: null,
    },
    il: {
        name: 'IL',
        monaco: 'asm',
        extensions: ['.il'],
        alias: [],
        logoFilename: 'dotnet.svg',
        logoFilenameDark: null,
        formatter: null,
        previewFilter: null,
        monacoDisassembly: null,
    },
    ispc: {
        name: 'ispc',
        monaco: 'ispc',
        extensions: ['.ispc'],
        alias: [],
        logoFilename: 'ispc.png',
        logoFilenameDark: null,
        formatter: null,
        previewFilter: null,
        monacoDisassembly: null,
    },
    java: {
        name: 'Java',
        monaco: 'java',
        extensions: ['.java'],
        alias: [],
        logoFilename: 'java.svg',
        logoFilenameDark: null,
        formatter: 'clangformat',
        previewFilter: null,
        monacoDisassembly: null,
        digitSeparator: '_',
    },
    julia: {
        name: 'Julia',
        monaco: 'julia',
        extensions: ['.jl'],
        alias: [],
        logoFilename: 'julia.svg',
        logoFilenameDark: null,
        formatter: null,
        previewFilter: null,
        monacoDisassembly: null,
        digitSeparator: '_',
    },
    kotlin: {
        name: 'Kotlin',
        monaco: 'kotlin',
        extensions: ['.kt'],
        alias: [],
        logoFilename: 'kotlin.svg',
        logoFilenameDark: null,
        formatter: null,
        previewFilter: null,
        monacoDisassembly: null,
        digitSeparator: '_',
    },
    lean: {
        name: 'Lean',
        monaco: 'lean',
        extensions: ['.lean'],
        alias: [],
        logoFilename: 'lean.png',
        logoFilenameDark: null,
        formatter: null,
        previewFilter: null,
        monacoDisassembly: null,
        digitSeparator: '_',
    },
    llvm: {
        name: 'LLVM IR',
        monaco: 'llvm-ir',
        extensions: ['.ll'],
        alias: [],
        logoFilename: 'llvm.png',
        logoFilenameDark: null,
        formatter: null,
        previewFilter: null,
        monacoDisassembly: null,
    },
    llvm_mir: {
        name: 'LLVM MIR',
        monaco: 'llvm-ir',
        extensions: ['.mir'],
        alias: [],
        logoFilename: 'llvm.png',
        logoFilenameDark: null,
        formatter: null,
        previewFilter: null,
        monacoDisassembly: null,
    },
    lua: {
        name: 'Lua',
        monaco: 'lua',
        extensions: ['.lua'],
        alias: [],
        logoFilename: 'lua.png',
        logoFilenameDark: null,
        formatter: null,
        previewFilter: null,
        monacoDisassembly: null,
    },
    modula2: {
        name: 'Modula-2',
        monaco: 'modula2',
        extensions: ['.mod'],
        alias: [],
        logoFilename: null,
        logoFilenameDark: null,
        formatter: null,
        previewFilter: null,
        monacoDisassembly: null,
    },
    mojo: {
        name: 'Mojo',
        monaco: 'mojo',
        extensions: ['.mojo', '.🔥'],
        alias: [],
        logoFilename: 'mojo.svg',
        logoFilenameDark: null,
        formatter: 'mblack',
        previewFilter: null,
        monacoDisassembly: null,
        digitSeparator: '_',
    },
    nim: {
        name: 'Nim',
        monaco: 'nim',
        extensions: ['.nim'],
        alias: [],
        logoFilename: 'nim.png',
        logoFilenameDark: null,
        formatter: null,
        previewFilter: null,
        monacoDisassembly: null,
    },
    numba: {
        name: 'Numba',
        monaco: 'python',
        extensions: ['.py'],
        alias: [],
        logoFilename: 'numba.svg',
        logoFilenameDark: null,
        formatter: null,
        previewFilter: null,
        monacoDisassembly: null,
    },
    nix: {
        name: 'Nix',
        monaco: 'nix',
        extensions: ['.nix'],
        alias: [],
        logoFilename: 'nix.svg',
        logoFilenameDark: null,
        formatter: null,
        previewFilter: null,
        monacoDisassembly: null,
    },
    objc: {
        name: 'Objective-C',
        monaco: 'objective-c',
        extensions: ['.m'],
        alias: [],
        logoFilename: null,
        logoFilenameDark: null,
        formatter: 'clangformat',
        previewFilter: null,
        monacoDisassembly: null,
    },
    'objc++': {
        name: 'Objective-C++',
        monaco: 'objective-c',
        extensions: ['.mm'],
        alias: [],
        logoFilename: null,
        logoFilenameDark: null,
        formatter: 'clangformat',
        previewFilter: null,
        monacoDisassembly: null,
        digitSeparator: "'",
    },
    ocaml: {
        name: 'OCaml',
        monaco: 'ocaml',
        extensions: ['.ml', '.mli'],
        alias: [],
        logoFilename: 'ocaml.svg',
        logoFilenameDark: null,
        formatter: null,
        previewFilter: null,
        monacoDisassembly: null,
    },
    odin: {
        name: 'Odin',
        monaco: 'odin',
        extensions: ['.odin'],
        alias: [],
        logoFilename: 'odin.png',
        logoFilenameDark: null,
        formatter: null,
        previewFilter: null,
        monacoDisassembly: null,
    },
    openclc: {
        name: 'OpenCL C',
        monaco: 'openclc',
        extensions: ['.cl', '.ocl'],
        alias: [],
        logoFilename: 'opencl.svg',
        logoFilenameDark: 'opencl-dark.svg',
        formatter: null,
        previewFilter: null,
        monacoDisassembly: null,
    },
    pascal: {
        name: 'Pascal',
        monaco: 'pascal',
        extensions: ['.pas', '.dpr', '.inc'],
        alias: [],
        logoFilename: 'pascal.svg', // TODO: Find a better alternative
        logoFilenameDark: 'pascal-dark.svg',
        formatter: null,
        previewFilter: null,
        monacoDisassembly: null,
    },
    perl: {
        name: 'Perl',
        monaco: 'perl',
        extensions: ['.pl', '.pm'],
        alias: [],
        logoFilename: 'perl.svg',
        logoFilenameDark: null,
        formatter: null,
        previewFilter: null,
        monacoDisassembly: null,
        digitSeparator: '_',
    },
    pony: {
        name: 'Pony',
        monaco: 'pony',
        extensions: ['.pony'],
        alias: [],
        logoFilename: 'pony.svg',
        logoFilenameDark: null,
        formatter: null,
        previewFilter: null,
        monacoDisassembly: null,
    },
    ptx: {
        name: 'PTX',
        monaco: 'ptx',
        extensions: ['.ptx'],
        alias: [],
        logoFilename: 'cuda.svg',
        logoFilenameDark: 'cuda-dark.svg',
        formatter: null,
        previewFilter: null,
        monacoDisassembly: null,
    },
    python: {
        name: 'Python',
        monaco: 'python',
        extensions: ['.py'],
        alias: [],
        logoFilename: 'python.svg',
        logoFilenameDark: null,
        formatter: null,
        previewFilter: null,
        monacoDisassembly: null,
        digitSeparator: '_',
    },
    racket: {
        name: 'Racket',
        monaco: 'scheme',
        extensions: ['.rkt'],
        alias: [],
        logoFilename: 'racket.svg',
        logoFilenameDark: null,
        formatter: null,
        previewFilter: null,
        monacoDisassembly: 'scheme',
    },
    raku: {
        name: 'Raku',
        monaco: 'perl',
        extensions: ['.raku', '.rakutest', '.rakumod', '.rakudoc'],
        alias: ['Perl 6'],
        logoFilename: 'camelia.svg',
        logoFilenameDark: null,
        formatter: null,
        previewFilter: null,
        monacoDisassembly: null,
    },
    razorforge: {
        name: 'RazorForge',
        monaco: 'razorforge',
        extensions: ['.rf'],
        alias: [],
        logoFilename: null,
        logoFilenameDark: null,
        formatter: null,
        previewFilter: null,
        monacoDisassembly: 'llvm-ir',
    },
    ruby: {
        name: 'Ruby',
        monaco: 'ruby',
        extensions: ['.rb'],
        alias: [],
        logoFilename: 'ruby.svg',
        logoFilenameDark: null,
        formatter: null,
        previewFilter: null,
        monacoDisassembly: 'asmruby',
        digitSeparator: '_',
    },
    rust: {
        name: 'Rust',
        monaco: 'rustp',
        extensions: ['.rs'],
        alias: [],
        logoFilename: 'rust.svg',
        logoFilenameDark: 'rust-dark.svg',
        formatter: 'rustfmt',
        previewFilter: null,
        monacoDisassembly: null,
        digitSeparator: '_',
        noAsmHint:
            '# Tip: Small functions may be inlined and not appear in output.\n' +
            '# Use #[inline(never)] or #[unsafe(no_mangle)] to prevent this.\n' +
            '# For main(), declare it as pub fn main() to see it in output.',
    },
    sail: {
        name: 'Sail',
        monaco: 'sail',
        extensions: ['.sail'],
        alias: [],
        logoFilename: 'sail.svg',
        logoFilenameDark: null,
        formatter: null,
        previewFilter: null,
        monacoDisassembly: null,
    },
    sfpi: {
        name: 'SFPI C++',
        monaco: 'cppp',
        extensions: ['.cpp', '.h', '.hpp'],
        alias: ['sfpi', 'tt-sfpi'],
        logoFilename: 'cpp.svg',
        logoFilenameDark: null,
        formatter: 'clangformat',
        previewFilter: /^\s*#include/,
        monacoDisassembly: null,
        tooltip: 'Tenstorrent SFPI C++ for custom SFPU/Tensix kernel code',
        digitSeparator: "'",
    },

    snowball: {
        name: 'Snowball',
        monaco: 'swift',
        extensions: ['.sn'],
        alias: [],
        logoFilename: 'snowball.svg',
        logoFilenameDark: 'snowball.svg',
        formatter: null,
        previewFilter: null,
        monacoDisassembly: null,
    },
    scala: {
        name: 'Scala',
        monaco: 'scala',
        extensions: ['.scala'],
        alias: [],
        logoFilename: 'scala.png',
        logoFilenameDark: null,
        formatter: null,
        previewFilter: null,
        monacoDisassembly: null,
        digitSeparator: '_',
    },
    slang: {
        name: 'Slang',
        monaco: 'slang',
        extensions: ['.slang'],
        alias: [],
        logoFilename: 'slang.svg',
        logoFilenameDark: 'slang-dark.svg',
        formatter: null,
        previewFilter: null,
        monacoDisassembly: null,
    },
    solidity: {
        name: 'Solidity',
        monaco: 'sol',
        extensions: ['.sol'],
        alias: [],
        logoFilename: 'solidity.svg',
        logoFilenameDark: null,
        formatter: null,
        previewFilter: null,
        monacoDisassembly: null,
    },
    spice: {
        name: 'Spice',
        monaco: 'spice',
        extensions: ['.spice'],
        alias: [],
        logoFilename: 'spice.png',
        logoFilenameDark: null,
        formatter: null,
        previewFilter: null,
        monacoDisassembly: null,
    },
    spirv: {
        name: 'SPIR-V',
        monaco: 'spirv',
        extensions: ['.spvasm'],
        alias: [],
        logoFilename: 'spirv.svg',
        logoFilenameDark: 'spirv-dark.svg',
        formatter: null,
        previewFilter: null,
        monacoDisassembly: null,
    },
    swift: {
        name: 'Swift',
        monaco: 'swift',
        extensions: ['.swift'],
        alias: [],
        logoFilename: 'swift.svg',
        logoFilenameDark: null,
        formatter: null,
        previewFilter: null,
        monacoDisassembly: null,
        digitSeparator: '_',
    },
    tablegen: {
        name: 'LLVM TableGen',
        monaco: 'tablegen',
        extensions: ['.td'],
        alias: [],
        logoFilename: 'llvm.png',
        logoFilenameDark: null,
        formatter: null,
        previewFilter: null,
        monacoDisassembly: null,
    },
    toit: {
        name: 'Toit',
        monaco: 'toit',
        extensions: ['.toit'],
        alias: [],
        logoFilename: 'toit.svg',
        logoFilenameDark: null,
        formatter: null,
        previewFilter: null,
        monacoDisassembly: null,
    },
    triton: {
        name: 'Triton',
        monaco: 'python',
        extensions: ['.py'],
        alias: [],
        logoFilename: 'triton.png',
        logoFilenameDark: null,
        formatter: null,
        previewFilter: null,
        monacoDisassembly: null,
    },
    typescript: {
        name: 'TypeScript Native',
        monaco: 'typescript',
        extensions: ['.ts', '.d.ts'],
        alias: [],
        logoFilename: 'ts.svg',
        logoFilenameDark: null,
        formatter: null,
        previewFilter: null,
        monacoDisassembly: null,
        digitSeparator: '_',
    },
    v: {
        name: 'V',
        monaco: 'v',
        extensions: ['.v', '.vsh'],
        alias: [],
        logoFilename: 'v.svg',
        logoFilenameDark: null,
        formatter: 'vfmt',
        previewFilter: null,
        monacoDisassembly: 'nc',
    },
    vala: {
        name: 'Vala',
        monaco: 'vala',
        extensions: ['.vala'],
        alias: [],
        logoFilename: 'vala.svg',
        logoFilenameDark: null,
        formatter: null,
        previewFilter: null,
        monacoDisassembly: null,
    },
    vb: {
        name: 'Visual Basic',
        monaco: 'vb',
        extensions: ['.vb'],
        alias: [],
        logoFilename: 'dotnet.svg',
        logoFilenameDark: null,
        formatter: null,
        previewFilter: null,
        monacoDisassembly: null,
    },
    vyper: {
        name: 'Vyper',
        monaco: 'python',
        extensions: ['.vy'],
        alias: [],
        logoFilename: 'vyper.svg',
        logoFilenameDark: null,
        formatter: null,
        previewFilter: null,
        monacoDisassembly: null,
    },
    wasm: {
        name: 'WASM',
        monaco: 'wat',
        extensions: ['.wat'],
        alias: [],
        logoFilename: 'wasm.svg',
        logoFilenameDark: null,
        formatter: null,
        previewFilter: null,
        monacoDisassembly: null,
    },
    yul: {
        name: 'Yul (Solidity IR)',
        monaco: 'yul',
        extensions: ['.yul'],
        alias: [],
        logoFilename: 'solidity.svg',
        logoFilenameDark: null,
        formatter: null,
        previewFilter: null,
        monacoDisassembly: null,
    },
    zig: {
        name: 'Zig',
        monaco: 'zig',
        extensions: ['.zig'],
        alias: [],
        logoFilename: 'zig.svg',
        logoFilenameDark: null,
        formatter: null,
        previewFilter: null,
        monacoDisassembly: null,
        digitSeparator: '_',
    },
    javascript: {
        name: 'Javascript',
        monaco: 'typescript',
        extensions: ['.mjs'],
        alias: [],
        logoFilename: 'js.svg',
        logoFilenameDark: null,
        formatter: null,
        previewFilter: null,
        monacoDisassembly: null,
        digitSeparator: '_',
    },
    gimple: {
        name: 'GIMPLE',
        monaco: 'nc',
        extensions: ['.c'],
        alias: [],
        logoFilename: 'gimple.svg',
        logoFilenameDark: null,
        formatter: null,
        previewFilter: /^\s*#include/,
        monacoDisassembly: null,
    },
    ylc: {
        name: 'Ygen',
        monaco: 'llvm-ir',
        extensions: ['.yl'],
        alias: [],
        logoFilename: null, // ygen does not yet have a logo ping me if it requires one (@Cr0a3)
        logoFilenameDark: null,
        formatter: null,
        previewFilter: null,
        monacoDisassembly: null,
    },
    sway: {
        name: 'sway',
        monaco: 'sway',
        extensions: ['.sw'],
        alias: [],
        logoFilename: 'sway.svg',
        logoFilenameDark: null,
        formatter: null,
        previewFilter: null,
        monacoDisassembly: null,
        digitSeparator: '_',
    },
};

export const languages = Object.fromEntries(
    Object.entries(definitions).map(([key, lang]) => {
        let example: string;
        try {
            example = fs.readFileSync(path.join('examples', key, 'default' + lang.extensions[0]), 'utf8');
        } catch {
            example = 'Oops, something went wrong and we could not get the default code for this language.';
        }

        const def: Language = {
            ...lang,
            id: key as LanguageKey,
            supportsExecute: false,
            example,
        };
        return [key, def];
    }),
) as Record<LanguageKey, Language>;
