bigtext 0.9.0

Free editor for huge text and log files (1-50+ GB): opens instantly, never freezes, 2.5 GB/s search, atomic save
Documentation
//! Each programming language's comments and words for [`super::code`]. Keyword and type lists
//! are sorted byte-wise (a test checks).

use super::code::Spec;

pub(super) const C: Spec = Spec {
    line: &["//"],
    block: Some(("/*", "*/")),
    nest: false,
    keywords: C_KEYWORDS,
    types: C_TYPES,
    type_kw: &["class", "enum", "namespace", "new", "struct", "typename", "union"],
    fn_kw: &[],
    pascal: true,
    at_attr: false,
    ci: false,
    sync: &[
        "#define", "#if", "#ifdef", "#ifndef", "#include", "#pragma", "bool", "char", "class", "const", "double", "enum", "extern", "float", "inline", "int", "long",
        "namespace", "static", "struct", "template", "typedef", "union", "unsigned", "using", "void",
    ],
};

pub(super) const CSHARP: Spec = Spec {
    line: &["//"],
    block: Some(("/*", "*/")),
    nest: false,
    keywords: CSHARP_KEYWORDS,
    types: CSHARP_TYPES,
    type_kw: &["class", "enum", "interface", "namespace", "new", "record", "struct"],
    fn_kw: &[],
    pascal: true,
    at_attr: false,
    ci: false,
    sync: &["#region", "abstract", "class", "enum", "interface", "internal", "namespace", "partial", "public", "record", "sealed", "static", "struct", "using"],
};

pub(super) const JAVA: Spec = Spec {
    line: &["//"],
    block: Some(("/*", "*/")),
    nest: false,
    keywords: JAVA_KEYWORDS,
    types: JAVA_TYPES,
    type_kw: &["class", "enum", "extends", "implements", "interface", "new", "record"],
    fn_kw: &[],
    pascal: true,
    at_attr: true,
    ci: false,
    sync: &["@", "abstract", "class", "enum", "final", "import", "interface", "package", "public", "record"],
};

pub(super) const JS: Spec = Spec {
    line: &["//"],
    block: Some(("/*", "*/")),
    nest: false,
    keywords: JS_KEYWORDS,
    types: &[],
    type_kw: &["class", "extends", "new"],
    fn_kw: &["function"],
    pascal: true,
    at_attr: true,
    ci: false,
    sync: JS_SYNC,
};

pub(super) const TS: Spec = Spec {
    line: &["//"],
    block: Some(("/*", "*/")),
    nest: false,
    keywords: TS_KEYWORDS,
    types: TS_TYPES,
    type_kw: &["class", "enum", "extends", "implements", "interface", "namespace", "new", "type"],
    fn_kw: &["function"],
    pascal: true,
    at_attr: true,
    ci: false,
    sync: JS_SYNC,
};

pub(super) const GO: Spec = Spec {
    line: &["//"],
    block: Some(("/*", "*/")),
    nest: false,
    keywords: GO_KEYWORDS,
    types: GO_TYPES,
    type_kw: &["type"],
    fn_kw: &["func"],
    // Exported functions and variables are capitalised too.
    pascal: false,
    at_attr: false,
    ci: false,
    sync: &["const", "func", "import", "package", "type", "var"],
};

pub(super) const RUST: Spec = Spec {
    line: &["//"],
    block: Some(("/*", "*/")),
    nest: true,
    keywords: RUST_KEYWORDS,
    types: RUST_TYPES,
    type_kw: &["enum", "impl", "struct", "trait", "type"],
    fn_kw: &["fn"],
    pascal: true,
    at_attr: false,
    ci: false,
    sync: &["#[", "#![", "async", "const", "enum", "extern", "fn", "impl", "macro_rules!", "mod", "pub", "static", "struct", "trait", "type", "unsafe", "use"],
};

pub(super) const PHP: Spec = Spec {
    line: &["//", "#"],
    block: Some(("/*", "*/")),
    nest: false,
    keywords: PHP_KEYWORDS,
    types: PHP_TYPES,
    type_kw: &["class", "enum", "extends", "implements", "instanceof", "interface", "new", "trait"],
    fn_kw: &["fn", "function"],
    pascal: true,
    at_attr: false,
    ci: true,
    sync: &["<?php", "#[", "abstract", "class", "enum", "final", "function", "interface", "namespace", "trait", "use"],
};

pub(super) const PYTHON: Spec = Spec {
    line: &["#"],
    block: None,
    nest: false,
    keywords: PY_KEYWORDS,
    types: PY_TYPES,
    type_kw: &["class"],
    fn_kw: &["def"],
    pascal: true,
    at_attr: true,
    ci: false,
    sync: &["@", "async", "class", "def", "from", "if __name__", "import"],
};

pub(super) const SHELL: Spec = Spec {
    line: &["#"],
    block: None,
    nest: false,
    keywords: SH_KEYWORDS,
    types: &[],
    type_kw: &[],
    fn_kw: &["function"],
    pascal: false,
    at_attr: false,
    ci: false,
    sync: &["alias", "case", "declare", "export", "for", "function", "if", "readonly", "set", "source", "while"],
};

pub(super) const KOTLIN: Spec = Spec {
    line: &["//"],
    block: Some(("/*", "*/")),
    nest: true,
    keywords: KOTLIN_KEYWORDS,
    types: KOTLIN_TYPES,
    type_kw: &["class", "interface", "object", "typealias"],
    fn_kw: &["fun"],
    pascal: true,
    at_attr: true,
    ci: false,
    sync: &["@", "abstract", "class", "data", "enum", "fun", "import", "interface", "internal", "object", "open", "package", "private", "public", "sealed"],
};

pub(super) const SWIFT: Spec = Spec {
    line: &["//"],
    block: Some(("/*", "*/")),
    nest: true,
    keywords: SWIFT_KEYWORDS,
    types: SWIFT_TYPES,
    type_kw: &["actor", "class", "enum", "extension", "protocol", "struct", "typealias"],
    fn_kw: &["func"],
    pascal: true,
    at_attr: true,
    ci: false,
    sync: &["@", "actor", "class", "enum", "extension", "fileprivate", "final", "func", "import", "internal", "open", "private", "protocol", "public", "struct"],
};

pub(super) const DART: Spec = Spec {
    line: &["//"],
    block: Some(("/*", "*/")),
    nest: true,
    keywords: DART_KEYWORDS,
    types: DART_TYPES,
    type_kw: &["class", "enum", "extends", "implements", "mixin", "new", "typedef", "with"],
    fn_kw: &[],
    pascal: true,
    at_attr: true,
    ci: false,
    sync: &["@", "abstract", "class", "enum", "extension", "import", "library", "mixin", "part", "typedef", "void"],
};

const KOTLIN_KEYWORDS: &[&str] = &["abstract", "annotation", "as", "break", "by", "catch", "class", "companion", "const", "constructor", "continue", "crossinline", "data", "do", "else", "enum", "external", "false", "final", "finally", "for", "fun", "get", "if", "import", "in", "infix", "init", "inline", "inner", "interface", "internal", "is", "lateinit", "noinline", "null", "object", "open", "operator", "out", "override", "package", "private", "protected", "public", "reified", "return", "sealed", "set", "super", "suspend", "tailrec", "this", "throw", "true", "try", "typealias", "val", "value", "var", "vararg", "when", "where", "while"];
const KOTLIN_TYPES: &[&str] = &["Any", "Array", "Boolean", "Byte", "Char", "Double", "Float", "Int", "List", "Long", "Map", "MutableList", "MutableMap", "Nothing", "Set", "Short", "String", "UInt", "ULong", "Unit"];
const SWIFT_KEYWORDS: &[&str] = &["actor", "any", "as", "associatedtype", "async", "await", "break", "case", "catch", "class", "continue", "convenience", "default", "defer", "deinit", "didSet", "do", "dynamic", "else", "enum", "extension", "fallthrough", "false", "fileprivate", "final", "for", "func", "get", "guard", "if", "import", "in", "indirect", "infix", "init", "inout", "internal", "is", "lazy", "let", "mutating", "nil", "nonisolated", "nonmutating", "open", "operator", "optional", "override", "postfix", "precedencegroup", "prefix", "private", "protocol", "public", "repeat", "required", "rethrows", "return", "self", "set", "some", "static", "struct", "subscript", "super", "switch", "throw", "throws", "true", "try", "typealias", "unowned", "var", "weak", "where", "while", "willSet"];
const SWIFT_TYPES: &[&str] = &["Any", "AnyObject", "Array", "Bool", "Character", "Dictionary", "Double", "Float", "Int", "Int16", "Int32", "Int64", "Int8", "Optional", "Self", "Set", "String", "UInt", "UInt16", "UInt32", "UInt64", "UInt8", "Void"];
const DART_KEYWORDS: &[&str] = &["abstract", "as", "assert", "async", "await", "base", "break", "case", "catch", "class", "const", "continue", "covariant", "default", "deferred", "do", "dynamic", "else", "enum", "export", "extends", "extension", "external", "factory", "false", "final", "finally", "for", "get", "hide", "if", "implements", "import", "in", "interface", "is", "late", "library", "mixin", "new", "null", "of", "on", "operator", "part", "required", "rethrow", "return", "sealed", "set", "show", "static", "super", "switch", "sync", "this", "throw", "true", "try", "typedef", "var", "when", "while", "with", "yield"];
const DART_TYPES: &[&str] = &["Future", "Iterable", "List", "Map", "Never", "Null", "Object", "Set", "Stream", "String", "bool", "double", "int", "num", "void"];

pub(super) const RUBY: Spec = Spec {
    line: &["#"],
    block: Some(("=begin", "=end")),
    nest: false,
    keywords: RUBY_KEYWORDS,
    types: &[],
    type_kw: &["class", "module"],
    fn_kw: &["def"],
    pascal: true,
    at_attr: false,
    ci: false,
    sync: &["class", "def", "module", "require", "require_relative"],
};

pub(super) const LUA: Spec = Spec {
    line: &["--"],
    block: Some(("--[[", "]]")),
    nest: false,
    keywords: LUA_KEYWORDS,
    types: &[],
    type_kw: &[],
    fn_kw: &["function"],
    pascal: false,
    at_attr: false,
    ci: false,
    sync: &["function", "local"],
};

pub(super) const POWERSHELL: Spec = Spec {
    line: &["#"],
    block: Some(("<#", "#>")),
    nest: false,
    keywords: PS_KEYWORDS,
    types: PS_TYPES,
    type_kw: &["class", "enum"],
    fn_kw: &["filter", "function", "workflow"],
    pascal: false,
    at_attr: false,
    ci: true,
    sync: &["class", "function", "param", "using"],
};

const RUBY_KEYWORDS: &[&str] = &["BEGIN", "END", "__FILE__", "__LINE__", "__method__", "alias", "and", "attr_accessor", "attr_reader", "attr_writer", "begin", "break", "case", "class", "def", "defined?", "do", "else", "elsif", "end", "ensure", "extend", "false", "for", "if", "in", "include", "loop", "module", "module_function", "next", "nil", "not", "or", "private", "protected", "public", "raise", "redo", "require", "require_relative", "rescue", "retry", "return", "self", "super", "then", "true", "undef", "unless", "until", "when", "while", "yield"];
const LUA_KEYWORDS: &[&str] = &["and", "break", "do", "else", "elseif", "end", "false", "for", "function", "goto", "if", "in", "local", "nil", "not", "or", "repeat", "return", "self", "then", "true", "until", "while"];
const PS_KEYWORDS: &[&str] = &["begin", "break", "catch", "class", "clean", "continue", "data", "default", "do", "dynamicparam", "else", "elseif", "end", "enum", "exit", "filter", "finally", "for", "foreach", "function", "hidden", "if", "in", "param", "process", "return", "static", "switch", "throw", "trap", "try", "until", "using", "while", "workflow"];
const PS_TYPES: &[&str] = &["array", "bool", "byte", "char", "datetime", "decimal", "double", "float", "guid", "hashtable", "int", "int16", "int32", "int64", "long", "object", "pscustomobject", "psobject", "regex", "scriptblock", "string", "timespan", "uint32", "uint64", "void", "xml"];
/// PowerShell's operators after `-` (`-eq`, `-like`).
pub(super) const PS_OPERATORS: &[&str] = &["and", "as", "band", "bnot", "bor", "bxor", "ceq", "cge", "cgt", "ckeys", "cle", "clike", "clt", "cmatch", "cne", "cnotlike", "cnotmatch", "contains", "creplace", "csplit", "eq", "f", "ge", "gt", "ieq", "ilike", "imatch", "in", "ine", "inotlike", "inotmatch", "ireplace", "is", "isnot", "isplit", "join", "le", "like", "lt", "match", "ne", "not", "notcontains", "notin", "notlike", "notmatch", "or", "replace", "shl", "shr", "split", "xor"];

const PY_KEYWORDS: &[&str] = &[
    "False", "None", "True", "and", "as", "assert", "async", "await", "break", "case", "class", "cls", "continue", "def", "del", "elif", "else", "except",
    "finally", "for", "from", "global", "if", "import", "in", "is", "lambda", "match", "nonlocal", "not", "or", "pass", "raise", "return", "self", "try", "while",
    "with", "yield",
];
const PY_TYPES: &[&str] = &["bool", "bytearray", "bytes", "complex", "dict", "float", "frozenset", "int", "list", "object", "set", "str", "tuple", "type"];

const SH_KEYWORDS: &[&str] = &[
    "alias", "break", "case", "continue", "declare", "do", "done", "elif", "else", "esac", "eval", "exec", "exit", "export", "fi", "for", "function", "if", "in",
    "local", "readonly", "return", "select", "shift", "source", "then", "time", "trap", "typeset", "unset", "until", "while",
];
/// Shell built-in commands, coloured as functions.
pub(super) const SH_BUILTINS: &[&str] = &[
    "bg", "cd", "command", "echo", "enable", "false", "fg", "getopts", "hash", "jobs", "kill", "let", "mapfile", "popd", "printf", "pushd", "pwd", "read", "set",
    "shopt", "sleep", "test", "true", "type", "ulimit", "umask", "wait",
];

/// PHP's keywords in lower case (they are matched ignoring case).
const PHP_KEYWORDS: &[&str] = &[
    "__class__", "__dir__", "__file__", "__function__", "__line__", "__method__", "__namespace__", "__trait__", "abstract", "and", "array", "as", "break",
    "callable", "case", "catch", "class", "clone", "const", "continue", "declare", "default", "do", "echo", "else", "elseif", "empty", "enddeclare", "endfor",
    "endforeach", "endif", "endswitch", "endwhile", "enum", "extends", "false", "final", "finally", "fn", "for", "foreach", "function", "global", "goto", "if",
    "implements", "include", "include_once", "instanceof", "insteadof", "interface", "isset", "list", "match", "namespace", "new", "null", "or", "parent", "print",
    "private", "protected", "public", "readonly", "require", "require_once", "return", "self", "static", "switch", "throw", "trait", "true", "try", "unset", "use",
    "var", "while", "xor", "yield",
];
const PHP_TYPES: &[&str] = &["bool", "float", "int", "iterable", "mixed", "never", "object", "string", "void"];

const JS_SYNC: &[&str] =&["@", "abstract", "async", "class", "const", "declare", "enum", "export", "function", "import", "interface", "let", "namespace", "type", "var"];

const C_KEYWORDS: &[&str] = &[
    "_Alignas", "_Alignof", "_Atomic", "_Generic", "_Noreturn", "_Static_assert", "_Thread_local", "alignas", "alignof", "and", "and_eq", "asm", "auto", "bitand",
    "bitor", "break", "case", "catch", "class", "co_await", "co_return", "co_yield", "compl", "concept", "const", "const_cast", "consteval", "constexpr", "constinit",
    "continue", "decltype", "default", "delete", "do", "dynamic_cast", "else", "enum", "explicit", "export", "extern", "false", "final", "for", "friend", "goto",
    "if", "inline", "mutable", "namespace", "new", "noexcept", "not", "not_eq", "nullptr", "operator", "or", "or_eq", "override", "private", "protected", "public",
    "register", "reinterpret_cast", "requires", "restrict", "return", "sizeof", "static", "static_assert", "static_cast", "struct", "switch", "template", "this",
    "thread_local", "throw", "true", "try", "typedef", "typeid", "typename", "union", "using", "virtual", "volatile", "while", "xor", "xor_eq",
];
const C_TYPES: &[&str] = &[
    "FILE", "_Bool", "_Complex", "array", "bool", "char", "char16_t", "char32_t", "char8_t", "double", "float", "int", "int16_t", "int32_t", "int64_t", "int8_t",
    "intptr_t", "long", "map", "optional", "pair", "ptrdiff_t", "set", "shared_ptr", "short", "signed", "size_t", "ssize_t", "string", "uint16_t", "uint32_t",
    "uint64_t", "uint8_t", "uintptr_t", "unique_ptr", "unordered_map", "unordered_set", "unsigned", "vector", "void", "wchar_t", "wstring",
];

const CSHARP_KEYWORDS: &[&str] = &[
    "abstract", "and", "as", "async", "await", "base", "break", "case", "catch", "checked", "class", "const", "continue", "default", "delegate", "do", "dynamic",
    "else", "enum", "event", "explicit", "extern", "false", "finally", "fixed", "for", "foreach", "get", "goto", "if", "implicit", "in", "init", "interface",
    "internal", "is", "lock", "nameof", "namespace", "new", "not", "null", "operator", "or", "out", "override", "params", "partial", "private", "protected",
    "public", "readonly", "record", "ref", "required", "return", "sealed", "set", "sizeof", "stackalloc", "static", "struct", "switch", "this", "throw", "true",
    "try", "typeof", "unchecked", "unsafe", "using", "var", "virtual", "volatile", "when", "where", "while", "with", "yield",
];
const CSHARP_TYPES: &[&str] = &["bool", "byte", "char", "decimal", "double", "float", "int", "long", "nint", "nuint", "object", "sbyte", "short", "string", "uint", "ulong", "ushort", "void"];

const JAVA_KEYWORDS: &[&str] = &[
    "abstract", "assert", "break", "case", "catch", "class", "const", "continue", "default", "do", "else", "enum", "extends", "false", "final", "finally", "for",
    "goto", "if", "implements", "import", "instanceof", "interface", "native", "new", "null", "package", "permits", "private", "protected", "public", "record",
    "return", "sealed", "static", "strictfp", "super", "switch", "synchronized", "this", "throw", "throws", "transient", "true", "try", "var", "volatile", "when",
    "while", "yield",
];
const JAVA_TYPES: &[&str] = &["boolean", "byte", "char", "double", "float", "int", "long", "short", "void"];

const JS_KEYWORDS: &[&str] = &[
    "Infinity", "NaN", "as", "async", "await", "break", "case", "catch", "class", "const", "continue", "debugger", "default", "delete", "do", "else", "export",
    "extends", "false", "finally", "for", "from", "function", "if", "import", "in", "instanceof", "let", "new", "null", "of", "return", "static", "super",
    "switch", "this", "throw", "true", "try", "typeof", "undefined", "var", "void", "while", "with", "yield",
];
const TS_KEYWORDS: &[&str] = &[
    "Infinity", "NaN", "abstract", "as", "asserts", "async", "await", "break", "case", "catch", "class", "const", "continue", "debugger", "declare", "default",
    "delete", "do", "else", "enum", "export", "extends", "false", "finally", "for", "from", "function", "if", "implements", "import", "in", "infer", "instanceof",
    "interface", "is", "keyof", "let", "module", "namespace", "new", "null", "of", "override", "private", "protected", "public", "readonly", "return", "satisfies",
    "static", "super", "switch", "this", "throw", "true", "try", "type", "typeof", "undefined", "unique", "var", "while", "with", "yield",
];
const TS_TYPES: &[&str] = &["any", "bigint", "boolean", "never", "number", "object", "string", "symbol", "unknown", "void"];

const GO_KEYWORDS: &[&str] = &[
    "break", "case", "chan", "const", "continue", "default", "defer", "else", "fallthrough", "false", "for", "func", "go", "goto", "if", "import", "interface",
    "iota", "map", "nil", "package", "range", "return", "select", "struct", "switch", "true", "type", "var",
];
const GO_TYPES: &[&str] = &[
    "any", "bool", "byte", "comparable", "complex128", "complex64", "error", "float32", "float64", "int", "int16", "int32", "int64", "int8", "rune", "string",
    "uint", "uint16", "uint32", "uint64", "uint8", "uintptr",
];

const RUST_KEYWORDS: &[&str] = &[
    "Self", "as", "async", "await", "break", "const", "continue", "crate", "dyn", "else", "enum", "extern", "false", "fn", "for", "if", "impl", "in", "let",
    "loop", "match", "mod", "move", "mut", "pub", "ref", "return", "self", "static", "struct", "super", "trait", "true", "type", "unsafe", "use", "where", "while",
];
const RUST_TYPES: &[&str] = &["bool", "char", "f32", "f64", "i128", "i16", "i32", "i64", "i8", "isize", "str", "u128", "u16", "u32", "u64", "u8", "usize"];

/// After these words a `/` starts a regular expression, not a division.
pub(super) const JS_BEFORE_REGEX: &[&str] = &["await", "case", "delete", "do", "else", "in", "instanceof", "new", "of", "return", "throw", "typeof", "void", "yield"];

/// Keywords that are values (coloured as constants).
pub(super) const LITERALS: &[&str] = &["FALSE", "False", "NULL", "None", "TRUE", "True", "false", "iota", "nil", "null", "nullptr", "true", "undefined"];

#[cfg(test)]
pub(super) const ALL: &[&Spec] = &[&C, &CSHARP, &JAVA, &JS, &TS, &GO, &RUST, &PHP, &PYTHON, &SHELL, &KOTLIN, &SWIFT, &DART, &RUBY, &LUA, &POWERSHELL];