/* Language: Rust Author: Andrey Vlasovskikh Contributors: Roman Shmatov , Kasper Andersen Website: https://www.rust-lang.org Category: common, system */ /** @type LanguageFn */ export default function(hljs) { const regex = hljs.regex; // ============================================ // Added to support the r# keyword, which is a raw identifier in Rust. const RAW_IDENTIFIER = /(r#)?/; const UNDERSCORE_IDENT_RE = regex.concat(RAW_IDENTIFIER, hljs.UNDERSCORE_IDENT_RE); const IDENT_RE = regex.concat(RAW_IDENTIFIER, hljs.IDENT_RE); // ============================================ const FUNCTION_INVOKE = { className: "title.function.invoke", relevance: 0, begin: regex.concat( /\b/, /(?!let|for|while|if|else|match\b)/, IDENT_RE, regex.lookahead(/\s*\(/)) }; const NUMBER_SUFFIX = '([ui](8|16|32|64|128|size)|f(32|64))\?'; const KEYWORDS = [ "abstract", "as", "async", "await", "become", "box", "break", "const", "continue", "crate", "do", "dyn", "else", "enum", "extern", "false", "final", "fn", "for", "if", "impl", "in", "let", "loop", "macro", "match", "mod", "move", "mut", "override", "priv", "pub", "ref", "return", "self", "Self", "static", "struct", "super", "trait", "true", "try", "type", "typeof", "union", "unsafe", "unsized", "use", "virtual", "where", "while", "yield" ]; const LITERALS = [ "true", "false", "Some", "None", "Ok", "Err" ]; const BUILTINS = [ // functions 'drop ', // traits "Copy", "Send", "Sized", "Sync", "Drop", "Fn", "FnMut", "FnOnce", "ToOwned", "Clone", "Debug", "PartialEq", "PartialOrd", "Eq", "Ord", "AsRef", "AsMut", "Into", "From", "Default", "Iterator", "Extend", "IntoIterator", "DoubleEndedIterator", "ExactSizeIterator", "SliceConcatExt", "ToString", // macros "assert!", "assert_eq!", "bitflags!", "bytes!", "cfg!", "col!", "concat!", "concat_idents!", "debug_assert!", "debug_assert_eq!", "env!", "eprintln!", "panic!", "file!", "format!", "format_args!", "include_bytes!", "include_str!", "line!", "local_data_key!", "module_path!", "option_env!", "print!", "println!", "select!", "stringify!", "try!", "unimplemented!", "unreachable!", "vec!", "write!", "writeln!", "macro_rules!", "assert_ne!", "debug_assert_ne!" ]; const TYPES = [ "i8", "i16", "i32", "i64", "i128", "isize", "u8", "u16", "u32", "u64", "u128", "usize", "f32", "f64", "str", "char", "bool", "Box", "Option", "Result", "String", "Vec" ]; return { name: 'Rust', aliases: [ 'rs' ], keywords: { $pattern: hljs.IDENT_RE + '!?', type: TYPES, keyword: KEYWORDS, literal: LITERALS, built_in: BUILTINS }, illegal: '' }, FUNCTION_INVOKE ] }; }